Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(contracts,unlock-js): cleanup deprec versions #14050

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion governance/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ artifacts-zk
cache-zk

.openzeppelin
xcalled.tmp.json
xcalled.tmp.json
*.log
31 changes: 31 additions & 0 deletions governance/helpers/subgraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { networks } = require('@unlock-protocol/networks')

const fetchFromSubgraph = async ({ chainId, query }) => {
const { subgraph } = networks[chainId]

if (!subgraph || !subgraph.endpoint) {
console.log(
'Missing subGraphURI for this network. Can not fetch from The Graph'
)
return []
}

const q = await fetch(subgraph.endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query,
}),
})

const { data, errors } = await q.json()
if (errors) {
console.log('SUBGRAPH > [Error] while fetching the graph', errors)
return []
}
return data
}

module.exports = {
fetchFromSubgraph,
}
28 changes: 3 additions & 25 deletions governance/scripts/lock/listManagers.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const { ethers } = require('hardhat')
const { networks } = require('@unlock-protocol/networks')
const { fetchFromSubgraph } = require('../../helpers/subgraph')

async function main({ lockAddress }) {
const PublicLock = await ethers.getContractFactory('PublicLock')
const lock = PublicLock.attach(lockAddress)

const { chainId } = await ethers.provider.getNetwork()
const { subgraph } = networks[chainId]

if (!subgraph || !subgraph.endpoint) {
console.log(
'Missing subGraphURI for this network. Can not fetch from The Graph'
)
return []
}

const query = `
{
Expand All @@ -27,25 +19,11 @@ async function main({ lockAddress }) {
}
`

const q = await fetch(subgraph.endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query,
}),
})

const { data, errors } = await q.json()
if (errors) {
console.log('LOCK > Error while fetching the graph', errors)
return []
}

const {
locks: [{ LockManagers }],
} = data
const managers = LockManagers.map((m) => m.address)
} = await fetchFromSubgraph({ chainId, query })

const managers = LockManagers.map((m) => m.address)
console.log(
`LOCK > managers for the lock '${await lock.name()}' (${lockAddress}):`
)
Expand Down
146 changes: 146 additions & 0 deletions governance/scripts/lock/outdated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
const { fetchFromSubgraph } = require('../../helpers/subgraph')
const { networks } = require('@unlock-protocol/networks')

async function getAllReceipts({ timeLimit, chainId }) {
const limit = 1000
let skip = 0
let more = true
const receipts = []
while (more) {
// console.log(`fetching results from ${skip} to ${limit}`)
const receiptsQuery = `
{
receipts(
skip: ${skip}
first: ${limit}
where:{
timestamp_gte: ${timeLimit}
}
) {
lockAddress
}
}
`
const { receipts: results } = await fetchFromSubgraph({
chainId,
query: receiptsQuery,
})

if (results.length < limit) {
more = false
} else {
skip += limit
}
receipts.push(...results)
}
return receipts
}

async function getLockVersions({ chainId, lockAddresses }) {
const versionsQuery = `
{
locks(
orderBy: version
sortDirection: DESC
where:{
address_in: ${JSON.stringify(lockAddresses)}

}
) {
version
address
}
}
`

const { locks } = await fetchFromSubgraph({
chainId,
query: versionsQuery,
})

// append chainId
return locks.map((lock) => ({ ...lock, chainId }))
}

async function getAllLockVersionInfo({ chainId, timeLimit }) {
// get all receipts before the date
const receipts = await getAllReceipts({ chainId, timeLimit })

// parse all addresses
const lockAddresses = receipts
.map(({ lockAddress }) => lockAddress)
.reduce((prev, curr) => (!prev.includes(curr) ? [...prev, curr] : prev), [])

// get all receipts before the date
const versions = await getLockVersions({ chainId, lockAddresses })
const count = versions.reduce(
(prev, { version }) => ((prev[version] = (prev[version] || 0) + 1), prev),
{}
)
const earliest = Object.keys(count)[0]
const earliestLocks = versions.filter(({ version }) => version == earliest)
return {
chainId,
receipts,
lockAddresses,
earliest,
earliestLocks,
count,
}
}

function logLocks({
chainId,
receipts,
lockAddresses,
earliest,
earliestLocks,
count,
}) {
const { name } = networks[chainId]
console.log(
`${name} (${chainId}):
- receipts: ${receipts.length}
- locks: ${lockAddresses.length} unique lock addresses
- earliest version ${earliest}
- earliest ${earliestLocks.length} locks (${parseInt(earliest) < 9 ? earliestLocks.map(({ address }) => address).join(',') : ''})
- versions: ${Object.keys(count)
.map((v) => `v${v}:${count[v]}`)
.join(',')}
`
)
}

async function main({ deadline = '2022-01-01' } = {}) {
console.log(`Before ${deadline}`)
const timeLimit = new Date(deadline).getTime() / 1000

const chains = Object.keys(networks).filter(
(id) => !isNaN(parseInt(id)) && !networks[id].isTestNetwork
)
console.log(`Chains: ${chains.join(',')} `)
const infos = {}
await Promise.all(
chains.map(async (chainId) => {
try {
const info = await getAllLockVersionInfo({ chainId, timeLimit })
infos[chainId] = info
logLocks(info)
} catch (error) {
console.log(`Couldn't fetch chain ${chainId}: ${error.message}`)
}
})
)
}

// execute as standalone
if (require.main === module) {
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
}

module.exports = main
9 changes: 0 additions & 9 deletions packages/contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ const settings = {
module.exports = {
solidity: {
compilers: [
{ version: '0.4.24', settings },
{ version: '0.4.25', settings },
{ version: '0.5.0', settings },
{ version: '0.5.12', settings },
{ version: '0.5.17', settings },
{ version: '0.5.14', settings },
{ version: '0.5.7', settings },
{ version: '0.5.9', settings },
{ version: '0.6.12', settings },
{ version: '0.7.6', settings },
{ version: '0.8.0', settings },
{ version: '0.8.2', settings },
Expand Down