diff --git a/.changeset/tall-items-exercise.md b/.changeset/tall-items-exercise.md new file mode 100644 index 000000000..967f29a05 --- /dev/null +++ b/.changeset/tall-items-exercise.md @@ -0,0 +1,6 @@ +--- +"@graphprotocol/sdk": minor +"@graphprotocol/contracts": patch +--- + +feat(utils): add utility to parse subgraph ids diff --git a/packages/contracts/scripts/ops/20240208-migrate-legacy-subgraphs/data.json b/packages/contracts/scripts/ops/20240208-migrate-legacy-subgraphs/data.json new file mode 100644 index 000000000..9ec23ad5b --- /dev/null +++ b/packages/contracts/scripts/ops/20240208-migrate-legacy-subgraphs/data.json @@ -0,0 +1,342 @@ +{ + "data": { + "subgraphs": [ + { + "id": "HXFFyPyPtUrBC78p2bntnQu7rXPKo79GA5wQQ2YxLtTE", + "owner": { + "id": "0x4bb4c1b0745ef7b4642feeccd0740dec417ca0a0" + }, + "subgraphNumber": "3", + "metadataHash": "0x8cf2627713b50bce6551ad0451f73517cf731431daecd557114cc3cd6d0e1a4a" + }, + { + "id": "2Kr8drrtxmCN7vbpD6NYHSkNTNBv5pQRVtSNi4m4UvRF", + "owner": { + "id": "0xbeb1faa6e7e39c7d9bdab03a7a362fe9d73d7c61" + }, + "subgraphNumber": "0", + "metadataHash": "0x0c4b3bea53d0f01dd74d57ce5408aaadba15df4077cc3dc38085dd3796eeda03" + }, + { + "id": "2qdAX71bB2DfXbNKgpTv3b5gY4EnfYNQVpL71o7e7nEz", + "owner": { + "id": "0xefe232372e2e30951fa90d7a800d5938eedc935d" + }, + "subgraphNumber": "0", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "ba7J1xjrWGhVk5Hbonf42Fv6B9MZdzs6pN3nzeRfYzY", + "owner": { + "id": "0xadafc1e419d03c84661b00c022ecd0101f190172" + }, + "subgraphNumber": "0", + "metadataHash": "0xc0e9a91e403be87c55494a6e74f493a3da829cc9cd0bc603472212cb68641f3b" + }, + { + "id": "HJxHihBy3o1na3FDuMBPXL9ytwgP64wu3wDWZGWst3w2", + "owner": { + "id": "0x33d0d63a1f0da691b283aedd29875afeaf98e6ba" + }, + "subgraphNumber": "1", + "metadataHash": "0x2f44901f32e2d14363a5237687b8daa8e724e359df8378e997c84f1c387bc32d" + }, + { + "id": "Druh8CtrwDPwwWNdG2FPEZUeR3XP39BzvJ6QW2cZUX1N", + "owner": { + "id": "0x9f9b34c201efe888b02fdcab52422199957a0407" + }, + "subgraphNumber": "1", + "metadataHash": "0x2f44901f32e2d14363a5237687b8daa8e724e359df8378e997c84f1c387bc32d" + }, + { + "id": "DncWyiEVwDE7RDgDgbWupaqwLvnKC78xHVyRCc6Ys6M4", + "owner": { + "id": "0x33d0d63a1f0da691b283aedd29875afeaf98e6ba" + }, + "subgraphNumber": "0", + "metadataHash": "0x2f44901f32e2d14363a5237687b8daa8e724e359df8378e997c84f1c387bc32d" + }, + { + "id": "6N1FHPcJ1sQCBzmWrrNntLibGRvGHJiWWFRY7LJcmtHJ", + "owner": { + "id": "0x9f9b34c201efe888b02fdcab52422199957a0407" + }, + "subgraphNumber": "0", + "metadataHash": "0x2f44901f32e2d14363a5237687b8daa8e724e359df8378e997c84f1c387bc32d" + }, + { + "id": "okz4sT96je97dMiAJtPYmkBwDN9rov9mcMYTPskGtrq", + "owner": { + "id": "0x534a9ac3d3401f80800375680bded6a84137d296" + }, + "subgraphNumber": "4", + "metadataHash": "0xff8e9977885ae9aad139fcb0eefe78ab66ff374f86d491e878006c7d2a1c0070" + }, + { + "id": "HNWN5ymGqWGpvBbYFRyebhdGeSac3CDEssY3dpoMKgdK", + "owner": { + "id": "0xa508c16666c5b8981fa46eb32784fccc01942a71" + }, + "subgraphNumber": "0", + "metadataHash": "0xbf9b4090ff738cb433e532263065756284dc57c4092ef377f52a445e3322976d" + }, + { + "id": "Gv1rewdMuEeDQ9sWsWMjJfwKWrTxo5e19vgxr1br7Ut4", + "owner": { + "id": "0x673b6e9fe607f6ddf4a4f25b386b846c5c82995e" + }, + "subgraphNumber": "0", + "metadataHash": "0xddb85d0e63098b79b4340052b866c4d8eb638a81d74c6e135c979d23f4d1e93f" + }, + { + "id": "GNpbzUsp352dYJwP7jEL7yRJqA7uf4zfoLAHk5PiMMJu", + "owner": { + "id": "0xde0c83462a75036b74928865941b97d83a4bc994" + }, + "subgraphNumber": "0", + "metadataHash": "0x67e55fbda97b73cdb4a92f475568f27f054c6e97e8286c51256a79df9d3eb826" + }, + { + "id": "Fzw1DXaBaSeBAqg4R6qa8KZDTp7j1jpNhfAP9fpHkCGb", + "owner": { + "id": "0x9e795fc1c644ecad8031ed52856fd64b65a678ac" + }, + "subgraphNumber": "0", + "metadataHash": "0xa035f76b2dc73756a5209382a1fbf22fc714027d687439a478f7e1d38aba22ec" + }, + { + "id": "FTTVbaL4HBzjhzgstyLEhN3WrjEMDB8owqfLARNtJ2FX", + "owner": { + "id": "0xefe232372e2e30951fa90d7a800d5938eedc935d" + }, + "subgraphNumber": "4", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "EtGRQWQruHSy9sZUHwX4FKXQPT3p15xsV6Bx3Pt5LMHU", + "owner": { + "id": "0x03c65e533cc73cc65cd71a0cb65efa4b11e74c22" + }, + "subgraphNumber": "3", + "metadataHash": "0x3b9721ef654fc1de4fb3654d8b27eb152face455c64bab02011e417575cc1077" + }, + { + "id": "EsEnqMt8GrWXSWjdkTphcauCRvcyC1eC4U9sdBRZEB84", + "owner": { + "id": "0x5991a31ab4095cb5470a5bd532e02568393b06d5" + }, + "subgraphNumber": "1", + "metadataHash": "0x56899ebbe432ee9fe47db5fe709b0c47ef0e0fbe3cc5a7fde97861b0ff37cb41" + }, + { + "id": "E1vew3qN9voUJCmkPWUubQBBppiBuC2f3T2Exh2CsyDH", + "owner": { + "id": "0xefe232372e2e30951fa90d7a800d5938eedc935d" + }, + "subgraphNumber": "2", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "Dz55sRXXemD3QUos3orXQWm5GQs3ACECGDbE86ZVsyrG", + "owner": { + "id": "0x03c65e533cc73cc65cd71a0cb65efa4b11e74c22" + }, + "subgraphNumber": "4", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "DSpmdAKr3pzkcU5R6NgreBsYabdkY9C5ocBbP9Sk4FAA", + "owner": { + "id": "0x5ca1ea5549e4e7cb64ae35225e11865d2572b3f9" + }, + "subgraphNumber": "0", + "metadataHash": "0x7369f32b51f12127e0591f079c99f6b997d90aecbd938270c0d0ecf902edfb2a" + }, + { + "id": "CvkpgHJW4ApYwYX831M8GpN472FbnhGKjdL2ERT5wie9", + "owner": { + "id": "0x9d196973c0c5bd65ccfb797a2c23eb5c1faba7ab" + }, + "subgraphNumber": "1", + "metadataHash": "0x82a07620f76548e3d7b38b468b9b67b2e9355a3dcef48ac1a4ebf96eb588685e" + }, + { + "id": "BM3vXF5bRFy4NRYrYirEnkfNsi3veUetKrqvqxmwMPSP", + "owner": { + "id": "0x03c65e533cc73cc65cd71a0cb65efa4b11e74c22" + }, + "subgraphNumber": "0", + "metadataHash": "0xbd37407528628edbdc2703dd0297097e41bb95b101c382d6f8fddcd8f15df58a" + }, + { + "id": "B39LecV8UELFUxULRswPhcifsZWJ6qaLL29cGYMcCK4s", + "owner": { + "id": "0x534a9ac3d3401f80800375680bded6a84137d296" + }, + "subgraphNumber": "3", + "metadataHash": "0xeeee64a3f268f229331f0088d0ef92b65257eee2a50492ed763dd21254c00799" + }, + { + "id": "A4xtyhChUywTCww37fFBtjd1poY2kHtMNu2fwKuxSSB", + "owner": { + "id": "0xa508c16666c5b8981fa46eb32784fccc01942a71" + }, + "subgraphNumber": "2", + "metadataHash": "0x7a7ca98b60850593645a9348d47143c7f550e790e48e51c4820baddd92319d35" + }, + { + "id": "9xL1fnWqqQ4QjC9Z33hTXkgPBZAHU14Tzqzf5mEtDbxM", + "owner": { + "id": "0xefe232372e2e30951fa90d7a800d5938eedc935d" + }, + "subgraphNumber": "3", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "9js1z4GHLYQuGQ6yGs9SdcCRUDTCXBLKY7e37KFUKRre", + "owner": { + "id": "0x69aa76325b4890f0fa9b44f4d99d56f3834738b4" + }, + "subgraphNumber": "0", + "metadataHash": "0xcaf93a686e6b7f7d1b78543ffc512d4046b493b4d125dc3c6fc5469c4af57d70" + }, + { + "id": "9EjsLLp4Ti39xUfZE1Xzz6bjwuzJSc3tVb3FvYxugq65", + "owner": { + "id": "0x03c65e533cc73cc65cd71a0cb65efa4b11e74c22" + }, + "subgraphNumber": "2", + "metadataHash": "0x3b9721ef654fc1de4fb3654d8b27eb152face455c64bab02011e417575cc1077" + }, + { + "id": "8mteqsnKePqyqAXVb6e6KkcBqJpR3tjwPacgP1jSmxSE", + "owner": { + "id": "0x5991a31ab4095cb5470a5bd532e02568393b06d5" + }, + "subgraphNumber": "3", + "metadataHash": "0x7876a5e7860a6abe0acebdde502d39b180856c41163d536fa632725f1f58cd3b" + }, + { + "id": "7Y8ZaLST7xYVcVZsVRiRw2xhnDe9C62nLmLQpxffPVj", + "owner": { + "id": "0xefe232372e2e30951fa90d7a800d5938eedc935d" + }, + "subgraphNumber": "6", + "metadataHash": "0xbdfd81ed973596a181375b4e3c69d5a1fe52d2c41a07ec0ba5621a1e2bd35ddb" + }, + { + "id": "7fspzcqYDgVF1gV7VxyA2k833EmhYqnsgRvXk9YAEPT4", + "owner": { + "id": "0xa508c16666c5b8981fa46eb32784fccc01942a71" + }, + "subgraphNumber": "1", + "metadataHash": "0x7400f53d252f899ec54094484d9dc3102e38147755f7dbf9ddb3ad4e9487acb9" + }, + { + "id": "7Ew6SQmN1Xdjk5YEonqYAaT1v2HikNa92VZUQPpJ2QvX", + "owner": { + "id": "0x534a9ac3d3401f80800375680bded6a84137d296" + }, + "subgraphNumber": "5", + "metadataHash": "0x54bc59114d36eaec4ff6a196c6e40a33d4eca894c514f9b127238424a4188274" + }, + { + "id": "6SVLBaaAcujGWswitHpLixkgjQVZugrQHj8AihGJgFgD", + "owner": { + "id": "0xfcb576bc8ee187945fa00f0daa7bbe9c1b51b0c9" + }, + "subgraphNumber": "2", + "metadataHash": "0x7aba482a8b8b809d890f865548b5a2a194271ca9afcb0f5e47a604a286f4d9aa" + }, + { + "id": "6bsUMv2twT2SA9RCToCBDXfStADVvDh2nvEmSuX4F8kc", + "owner": { + "id": "0x0b1302c23d9eb4b42a74cbefc4f9b3081ff1bf18" + }, + "subgraphNumber": "0", + "metadataHash": "0xfa65e518e90b49586e173e29ae25202995c400ee021353d90c42b682c34494d6" + }, + { + "id": "6AmTt2V2PQiKJuHF6X1ySjJpNTuwzvUTmUQRYL74eFxT", + "owner": { + "id": "0xefe232372e2e30951fa90d7a800d5938eedc935d" + }, + "subgraphNumber": "5", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "5vhK8XAGXiK4zwGPcN2C63TjhAHtqyqoUcS6RGR5H86i", + "owner": { + "id": "0x673b6e9fe607f6ddf4a4f25b386b846c5c82995e" + }, + "subgraphNumber": "3", + "metadataHash": "0xddb85d0e63098b79b4340052b866c4d8eb638a81d74c6e135c979d23f4d1e93f" + }, + { + "id": "5qyjWvZ1FLwAsBeJvPuyvhBddJDavKYyyjdXQZ28REAJ", + "owner": { + "id": "0xf556322b497b475d535d0d4048f56c092a0ea3ad" + }, + "subgraphNumber": "1", + "metadataHash": "0x9bdee2ed59fcf9532df294d9b07fa1ef3c127a144658c35fa3c1d9fee4f7cc2a" + }, + { + "id": "57MzWCjGmKWrUYGHgEVne3ieFCXnwAUHKKDLXm4mJPJb", + "owner": { + "id": "0x03c65e533cc73cc65cd71a0cb65efa4b11e74c22" + }, + "subgraphNumber": "6", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "4MQwNPuso8ABKHhddwUmJCaPqg2w4Vst6B2pPr21Ygn9", + "owner": { + "id": "0xefe232372e2e30951fa90d7a800d5938eedc935d" + }, + "subgraphNumber": "1", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "47BEnfQFYjURYjD8r2JNoFjXkYHTqJ3xfcnrKUrbnTiq", + "owner": { + "id": "0x534a9ac3d3401f80800375680bded6a84137d296" + }, + "subgraphNumber": "2", + "metadataHash": "0xba7ebef4cc835813d6bdd70b2ee4db65594898e57e3412197964bd30b383e5fb" + }, + { + "id": "3zULJJdf5s9d87rn5aDgoT4pE5Uih3z6SAEumXy1dQqv", + "owner": { + "id": "0x03c65e533cc73cc65cd71a0cb65efa4b11e74c22" + }, + "subgraphNumber": "1", + "metadataHash": "0x45926246b7a13663ccacd05331419b7c2519bbc8b8bb6be89ab285022eb6e557" + }, + { + "id": "3sHuzLagq1T5yYrsctLtz7QdcNAGsdsodHk7j3g2mrVV", + "owner": { + "id": "0x03c65e533cc73cc65cd71a0cb65efa4b11e74c22" + }, + "subgraphNumber": "5", + "metadataHash": "0x5998fe5b6e689794aebf986beac1557367cba0f18d666bf8ec3aa037e6f08877" + }, + { + "id": "3caWu7riX9kGBe2zmXVc4V8vQQ5U1c3QAjzeSGNT7Jo", + "owner": { + "id": "0x072e829ff4e1c9bdb95acaf947f8ec262ecdf92f" + }, + "subgraphNumber": "0", + "metadataHash": "0x7f6fe58ac5f0c86007d61813897fcdb956f3f71e816f105b18f22cde4213ca20" + }, + { + "id": "2qbnVdk8RfatovF1sogHzH1eZ52DoziY6d7qR5KHzk8X", + "owner": { + "id": "0xc320812b4bbb7f2369ee1316fd703de403ad0d2e" + }, + "subgraphNumber": "0", + "metadataHash": "0xd9ff52d1ac82d8ebe295ee1bf3fd0f352eacb134039af2464342a7285cf0d921" + } + ] + } +} diff --git a/packages/contracts/scripts/ops/20240208-migrate-legacy-subgraphs/migrate.ts b/packages/contracts/scripts/ops/20240208-migrate-legacy-subgraphs/migrate.ts new file mode 100644 index 000000000..9e2cbdcba --- /dev/null +++ b/packages/contracts/scripts/ops/20240208-migrate-legacy-subgraphs/migrate.ts @@ -0,0 +1,63 @@ +import hre from 'hardhat' +import data from './data.json' +import { confirm, subgraphIdToHex } from '@graphprotocol/sdk' +import { BigNumber, ethers } from 'ethers' + +async function main() { + const graph = hre.graph() + const deployer = await graph.getDeployer() + + // First estimate cost + const gasEstimate = await data.data.subgraphs.reduce(async (acc, subgraph) => { + return (await acc).add( + await graph.contracts.L1GNS.connect(deployer).estimateGas.migrateLegacySubgraph( + subgraph.owner.id, + subgraph.subgraphNumber, + subgraph.metadataHash, + ), + ) + }, Promise.resolve(BigNumber.from(0))) + const gasPrice = await graph.provider.getGasPrice() + const cost = ethers.utils.formatEther(gasEstimate.mul(gasPrice)) + + // Ask for confirmation + if ( + !(await confirm( + `This script will migrate ${data.data.subgraphs.length} legacy subgraphs, with an approximate cost of ${cost} Ξ. Are you sure you want to continue?`, + false, + )) + ) + return + + // do it + for (const subgraph of data.data.subgraphs) { + console.log(`Migrating legacy subgraph ${subgraph.owner.id}/${subgraph.subgraphNumber}...`) + + const legacyKey = await graph.contracts.L1GNS.legacySubgraphKeys(subgraphIdToHex(subgraph.id)) + if (legacyKey.account !== ethers.constants.AddressZero) { + console.log(` - Already migrated, skipping`) + continue + } + try { + const tx = await graph.contracts.L1GNS.connect(deployer).migrateLegacySubgraph( + subgraph.owner.id, + subgraph.subgraphNumber, + subgraph.metadataHash, + ) + const receipt = await tx.wait() + if (receipt.status == 1) { + console.log(` ✔ Migration succeeded!`) + } else { + console.log(` ✖ Migration failed!`) + console.log(receipt) + } + } catch (error) { + console.log(error) + } + } +} + +main().catch((error) => { + console.error(error) + process.exitCode = 1 +}) diff --git a/packages/sdk/src/utils/bytes.ts b/packages/sdk/src/utils/bytes.ts index eeecb6063..551be450c 100644 --- a/packages/sdk/src/utils/bytes.ts +++ b/packages/sdk/src/utils/bytes.ts @@ -1,3 +1,8 @@ +import { ethers } from 'ethers' import { hexlify, randomBytes } from 'ethers/lib/utils' export const randomHexBytes = (n = 32): string => hexlify(randomBytes(n)) + +export const base58ToHex = (base58: string): string => { + return ethers.utils.hexlify(ethers.utils.base58.decode(base58)) +} diff --git a/packages/sdk/src/utils/subgraph.ts b/packages/sdk/src/utils/subgraph.ts index af5a28ef3..b696f60b8 100644 --- a/packages/sdk/src/utils/subgraph.ts +++ b/packages/sdk/src/utils/subgraph.ts @@ -1,6 +1,6 @@ import { BigNumber, ethers } from 'ethers' import { solidityKeccak256 } from 'ethers/lib/utils' -import { randomHexBytes } from './bytes' +import { base58ToHex, randomHexBytes } from './bytes' export interface PublishSubgraph { subgraphDeploymentID: string @@ -36,3 +36,8 @@ export const buildSubgraph = (): PublishSubgraph => { subgraphMetadata: randomHexBytes(), } } + +export const subgraphIdToHex = (id: string): string => { + id = id.startsWith('Qm') ? id : `Qm${id}` + return `0x${base58ToHex(id).slice(6)}` +}