-
-
Notifications
You must be signed in to change notification settings - Fork 237
/
unlock.js
41 lines (36 loc) · 1.13 KB
/
unlock.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
const { networks } = require('@unlock-protocol/networks')
const contracts = require('@unlock-protocol/contracts')
const ERC20_ABI = require('./ABIs/erc20.json')
export const getUnlock = async (unlockAddress) => {
const { ethers } = require('hardhat')
if (!unlockAddress) {
unlockAddress = await getUnlockAddress()
}
// get unlock instance (TODO: do not use code version but packaged version)
const { abi } = contracts['UnlockV12']
const unlock = await ethers.getContractAt(abi, unlockAddress)
return unlock
}
export const getUdt = async () => {
const { ethers } = require('hardhat')
const unlock = await getUnlock()
const udt = await ethers.getContractAt(ERC20_ABI, await unlock.udt())
return udt
}
export const getUnlockAddress = async () => {
const { unlockAddress } = await getNetwork()
return unlockAddress
}
export const getNetwork = async (chainId) => {
const { ethers } = require('hardhat')
if (!chainId) {
;({ chainId } = await ethers.provider.getNetwork())
}
return networks[chainId] || { name: 'localhost', id: chainId }
}
export default {
getUnlock,
getUnlockAddress,
getUdt,
getNetwork,
}