forked from airswap/airswap-protocols
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
97 lines (89 loc) · 2.9 KB
/
deploy.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
/* eslint-disable no-console */
const fs = require('fs')
const prettier = require('prettier')
const Confirm = require('prompt-confirm')
const { ethers, run } = require('hardhat')
const {
chainLabels,
ChainIds,
protocolFeeReceiverAddresses,
ADDRESS_ZERO,
} = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const poolDeploys = require('@airswap/pool/deploys.js')
const swapDeploys = require('../deploys.js')
const swapBlocks = require('../deploys-blocks.js')
const adapterDeploys = require('../deploys-adapters.js')
const config = require('./config.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')
async function main() {
await run('compile')
const prettierConfig = await prettier.resolveConfig('../deploys.js')
const [deployer] = await ethers.getSigners()
const chainId = await deployer.getChainId()
if (chainId === ChainIds.HARDHAT) {
console.log('Value for --network flag is required')
return
}
await displayDeployerInfo(deployer)
let requiredSenderKind
let protocolFee
if (config[chainId]) {
;({ requiredSenderKind, protocolFee } = config[chainId])
} else {
;({ requiredSenderKind, protocolFee } = config[ChainIds.MAINNET])
}
let protocolFeeReceiver = poolDeploys[chainId] || ADDRESS_ZERO
if (protocolFeeReceiverAddresses[chainId]) {
protocolFeeReceiver = protocolFeeReceiverAddresses[chainId]
}
console.log(`adapters: ${JSON.stringify(adapterDeploys[chainId])}`)
console.log(`requiredSenderKind: ${requiredSenderKind}`)
console.log(`protocolFee: ${protocolFee}`)
console.log(`protocolFeeReceiver: ${protocolFeeReceiver}`)
const prompt = new Confirm('Proceed to deploy?')
if (await prompt.run()) {
const swapFactory = await ethers.getContractFactory('Swap')
const swapContract = await swapFactory.deploy(
adapterDeploys[chainId],
requiredSenderKind,
protocolFee,
protocolFeeReceiver
)
console.log(
'Deploying...',
getReceiptUrl(chainId, swapContract.deployTransaction.hash)
)
await swapContract.deployed()
swapDeploys[chainId] = swapContract.address
fs.writeFileSync(
'./deploys.js',
prettier.format(
`module.exports = ${JSON.stringify(swapDeploys, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
swapBlocks[chainId] = (
await swapContract.deployTransaction.wait()
).blockNumber
fs.writeFileSync(
'./deploys-blocks.js',
prettier.format(
`module.exports = ${JSON.stringify(swapBlocks, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(`Deployed: ${swapDeploys[chainId]} @ ${swapBlocks[chainId]}`)
console.log(
`\nVerify with "yarn verify --network ${chainLabels[
chainId
].toLowerCase()}"\n`
)
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})