-
Notifications
You must be signed in to change notification settings - Fork 2
/
hardhat.config.ts
188 lines (163 loc) · 6.51 KB
/
hardhat.config.ts
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import { HardhatUserConfig, task } from 'hardhat/config'
import '@nomicfoundation/hardhat-toolbox'
import '@nomiclabs/hardhat-web3'
import '@nomiclabs/hardhat-ethers'
import 'hardhat-deploy'
import dotenv from 'dotenv'
import { Prepayment__factory } from '@bisonai/orakl-contracts'
dotenv.config()
let commonConfig = {}
if (process.env.PRIV_KEY) {
commonConfig = {
gas: 5_000_000,
accounts: [process.env.PRIV_KEY]
}
} else {
commonConfig = {
gas: 5_000_000,
accounts: {
mnemonic: process.env.MNEMONIC || ''
}
}
}
const config: HardhatUserConfig = {
solidity: {
version: '0.8.16',
settings: {
optimizer: {
enabled: true,
runs: 1000
}
}
},
networks: {
localhost: {
gas: 1_400_000,
gasPrice: 250_000_000_000,
...commonConfig,
url: process.env.PROVIDER || 'http://127.0.0.1:8545'
},
baobab: {
url: process.env.PROVIDER || 'https://public-en.kairos.node.kaia.io',
chainId: 1001,
...commonConfig,
gasPrice: 250_000_000_000
},
cypress: {
url: process.env.PROVIDER || 'https://public-en-cypress.klaytn.net',
...commonConfig,
gasPrice: 250_000_000_000
}
},
namedAccounts: {
deployer: {
default: 0
},
prepayment: {
baobab: '0x8d3A1663d10eEb0bC9C9e537e1BBeA69383194e7',
cypress: '0xc2C88492Cf7e5240C3EB49353539E75336960600',
localhost: '0x5FbDB2315678afecb367f032d93F642f64180aa3'
},
vrfCoordinator: {
baobab: '0xDA8c0A00A372503aa6EC80f9b29Cc97C454bE499',
cypress: '0x3F247f70DC083A2907B8E76635986fd09AA80EFb',
localhost: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512'
}
}
}
task('address', 'Convert mnemonic to address')
.addParam('mnemonic', "The account's mnemonic")
.setAction(async (taskArgs, hre) => {
const wallet = hre.ethers.Wallet.fromMnemonic(taskArgs.mnemonic)
console.log(wallet.address)
})
task('createAccount', 'Create new account').setAction(async (taskArgs, hre) => {
const { prepayment: prepaymentAddress } = await hre.getNamedAccounts()
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress)
const txReceipt = await (await prepayment.createAccount()).wait()
const accId = txReceipt.events[0].args.accId.toString()
console.log(`Account created with ID: ${accId}`)
})
task('cancelAccount', 'Cancel account')
.addParam('to', 'Account address')
.addOptionalParam('accountId', 'Account Id')
.setAction(async (taskArgs, hre) => {
const { prepayment: prepaymentAddress } = await hre.getNamedAccounts()
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress)
const accId = taskArgs.accountId || process.env.ACC_ID
const to = taskArgs.amount
const txReceipt = await (await prepayment.cancelAccount(accId, to)).wait()
console.log(txReceipt)
console.log(`Account canceled with ID: ${accId}`)
})
task('deposit', 'Deposit $KLAY to account')
.addParam('amount', 'The amount of $KLAY')
.addOptionalParam('accountId', 'Account Id')
.setAction(async (taskArgs, hre) => {
const accId = taskArgs.accountId || process.env.ACC_ID
const klayAmount = taskArgs.amount
if (accId) {
const { prepayment: prepaymentAddress } = await hre.getNamedAccounts()
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress)
const amount = ethers.utils.parseEther(klayAmount)
const txReceipt = await (await prepayment.deposit(accId, { value: amount })).wait()
const balance = txReceipt.events[0].args.newBalance.toString()
const newBalance = ethers.utils.formatEther(balance)
console.log(`Deposited ${klayAmount} $KLAY to account ${accId}`)
console.log(`Account balance after deposit: ${newBalance} $KLAY`)
} else {
console.log(`Prepayment accountId is not defined`)
}
})
task('withdraw', 'Withdraw $KLAY from account')
.addParam('amount', 'The amount of $KLAY')
.addOptionalParam('accountId', 'Account Id')
.setAction(async (taskArgs, hre) => {
const accId = taskArgs.accountId || process.env.ACC_ID
const klayAmount = taskArgs.amount
if (accId) {
const { prepayment: prepaymentAddress } = await hre.getNamedAccounts()
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress)
const amount = ethers.utils.parseEther(klayAmount)
const txReceipt = await (await prepayment.withdraw(accId, amount)).wait()
const balance = txReceipt.events[0].args.newBalance.toString()
const newBalance = ethers.utils.formatEther(balance)
console.log(`Withdrew ${klayAmount} $KLAY to account ${accId}`)
console.log(`Account balance after withdrawal: ${newBalance} $KLAY`)
} else {
console.log(`Prepayment accountId is not defined`)
}
})
task('addConsumer', 'Add consumer')
.addOptionalParam('consumer', 'Consumer Address')
.addOptionalParam('accountId', 'Account Id')
.setAction(async (taskArgs, hre) => {
const accId = taskArgs.accountId || process.env.ACC_ID
const consumerAddress = taskArgs.consumer || (await ethers.getContract('VRFConsumer')).address
if (accId && consumerAddress) {
const { prepayment: prepaymentAddress } = await hre.getNamedAccounts()
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress)
await (await prepayment.addConsumer(accId, consumerAddress)).wait()
console.log(`Added consumer ${consumerAddress} to prepayment account`)
} else {
if (!accId) console.log(`Prepayment accountId is not defined`)
if (!consumerAddress) console.log(`Consumer Address is not defined`)
}
})
task('removeConsumer', 'Remove consumer')
.addOptionalParam('consumer', 'Consumer Address')
.addOptionalParam('accountId', 'Account Id')
.setAction(async (taskArgs, hre) => {
const accId = taskArgs.accountId || process.env.ACC_ID
const consumerAddress = taskArgs.consumer || (await ethers.getContract('VRFConsumer')).address
if (accId && consumerAddress) {
const { prepayment: prepaymentAddress } = await hre.getNamedAccounts()
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress)
await (await prepayment.removeConsumer(accId, consumerAddress)).wait()
console.log(`Removed consumer ${consumerAddress} to prepayment account`)
} else {
if (!accId) console.log(`Prepayment accountId is not defined`)
if (!consumerAddress) console.log(`Consumer Address is not defined`)
}
})
export default config