diff --git a/src/contracts/RepoAbi.json b/src/contracts/RepoAbi.json deleted file mode 100644 index ec7e46ba..00000000 --- a/src/contracts/RepoAbi.json +++ /dev/null @@ -1,430 +0,0 @@ -[ - { - "constant": true, - "inputs": [], - "name": "hasInitialized", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_script", - "type": "bytes" - } - ], - "name": "getEVMScriptExecutor", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "getRecoveryVault", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "token", - "type": "address" - } - ], - "name": "allowRecoverability", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "appId", - "outputs": [ - { - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "getInitializationBlock", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_token", - "type": "address" - } - ], - "name": "transferToVault", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_sender", - "type": "address" - }, - { - "name": "_role", - "type": "bytes32" - }, - { - "name": "_params", - "type": "uint256[]" - } - ], - "name": "canPerform", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "getEVMScriptRegistry", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "CREATE_VERSION_ROLE", - "outputs": [ - { - "name": "", - "type": "bytes32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "kernel", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "isPetrified", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "versionId", - "type": "uint256" - }, - { - "indexed": false, - "name": "semanticVersion", - "type": "uint16[3]" - } - ], - "name": "NewVersion", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "executor", - "type": "address" - }, - { - "indexed": false, - "name": "script", - "type": "bytes" - }, - { - "indexed": false, - "name": "input", - "type": "bytes" - }, - { - "indexed": false, - "name": "returnData", - "type": "bytes" - } - ], - "name": "ScriptResult", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "vault", - "type": "address" - }, - { - "indexed": true, - "name": "token", - "type": "address" - }, - { - "indexed": false, - "name": "amount", - "type": "uint256" - } - ], - "name": "RecoverToVault", - "type": "event" - }, - { - "constant": false, - "inputs": [], - "name": "initialize", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_newSemanticVersion", - "type": "uint16[3]" - }, - { - "name": "_contractAddress", - "type": "address" - }, - { - "name": "_contentURI", - "type": "bytes" - } - ], - "name": "newVersion", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "getLatest", - "outputs": [ - { - "name": "semanticVersion", - "type": "uint16[3]" - }, - { - "name": "contractAddress", - "type": "address" - }, - { - "name": "contentURI", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_contractAddress", - "type": "address" - } - ], - "name": "getLatestForContractAddress", - "outputs": [ - { - "name": "semanticVersion", - "type": "uint16[3]" - }, - { - "name": "contractAddress", - "type": "address" - }, - { - "name": "contentURI", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_semanticVersion", - "type": "uint16[3]" - } - ], - "name": "getBySemanticVersion", - "outputs": [ - { - "name": "semanticVersion", - "type": "uint16[3]" - }, - { - "name": "contractAddress", - "type": "address" - }, - { - "name": "contentURI", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_versionId", - "type": "uint256" - } - ], - "name": "getByVersionId", - "outputs": [ - { - "name": "semanticVersion", - "type": "uint16[3]" - }, - { - "name": "contractAddress", - "type": "address" - }, - { - "name": "contentURI", - "type": "bytes" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "getVersionsCount", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_oldVersion", - "type": "uint16[3]" - }, - { - "name": "_newVersion", - "type": "uint16[3]" - } - ], - "name": "isValidBump", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "pure", - "type": "function" - } -] diff --git a/src/tasks/generatePublishTx.ts b/src/tasks/generatePublishTx.ts index f7e9d7ec..42f71830 100644 --- a/src/tasks/generatePublishTx.ts +++ b/src/tasks/generatePublishTx.ts @@ -12,8 +12,7 @@ import { CliGlobalOptions, ListrContextBuildAndPublish } from "../types.js"; import { readManifest } from "../files/index.js"; import { ApmRepository } from "@dappnode/toolkit"; import registryAbi from "../contracts/ApmRegistryAbi.json" assert { type: "json" }; -import { semverToArray } from "../utils/semverToArray.js"; -import repoAbi from "../contracts/RepoAbi.json" assert { type: "json" }; +import { semverToArrayOfBigNumberish } from "../utils/semverToArrayOfBigNumberish.js"; const isZeroAddress = (address: string): boolean => parseInt(address) === 0; @@ -62,14 +61,15 @@ export function generatePublishTx({ task: async ctx => { try { const repository = await apm.getRepoContract(ensName); + ctx.txData = { to: await repository.getAddress(), value: 0, - data: encodeNewVersionCall({ - version: currentVersion, + data: await repository.newVersion( + semverToArrayOfBigNumberish(currentVersion), contractAddress, contentURI - }), + ).then(tx => tx.data), gasLimit: 300000, ensName, currentVersion, @@ -106,10 +106,12 @@ with command option: ); } + ctx.txData = { to: registryAddress, value: 0, - data: encodeNewRepoWithVersionCall({ + data: + encodeNewRepoWithVersionCall({ name: shortName, developerAddress, version: currentVersion, @@ -145,33 +147,6 @@ with command option: ); } -// Utils - - -/** - * newVersion( - * uint16[3] _newSemanticVersion, - * address _contractAddress, - * bytes _contentURI - * ) - */ -export function encodeNewVersionCall({ - version, - contractAddress, - contentURI -}: { - version: string; - contractAddress: string; - contentURI: string; -}): string { - const repo = ethers.Interface.from(repoAbi) - return repo.encodeFunctionData("newVersion", [ - semverToArray(version), // uint16[3] _newSemanticVersion - contractAddress, // address _contractAddress - contentURI // bytes _contentURI - ]); -} - /** * newRepoWithVersion( * string _name, @@ -198,7 +173,7 @@ export function encodeNewRepoWithVersionCall({ return registry.encodeFunctionData("newRepoWithVersion", [ name, // string _name developerAddress, // address _dev - semverToArray(version), // uint16[3] _initialSemanticVersion + semverToArrayOfBigNumberish(version), // uint16[3] _initialSemanticVersion contractAddress, // address _contractAddress contentURI // bytes _contentURI ]); diff --git a/src/utils/semverToArray.ts b/src/utils/semverToArray.ts deleted file mode 100644 index 64aefe11..00000000 --- a/src/utils/semverToArray.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Parses a semver version to the format necessary for an APM repo - * @param semver = 0.1.8 - * @return [0, 1, 8] - */ -export function semverToArray(semver: string): string[] { - return semver.split("."); -} diff --git a/src/utils/semverToArrayOfBigNumberish.ts b/src/utils/semverToArrayOfBigNumberish.ts new file mode 100644 index 00000000..fc8e9c80 --- /dev/null +++ b/src/utils/semverToArrayOfBigNumberish.ts @@ -0,0 +1,13 @@ +import { BigNumberish } from "ethers"; + +/** + * Parses a semver version to the format necessary for an APM repo + * @param semver = 0.1.8 + * @return [0, 1, 8] + */ +export function semverToArrayOfBigNumberish( + semver: string +): [BigNumberish, BigNumberish, BigNumberish] { + const [major, minor, patch] = semver.split(".").map(Number); + return [major, minor, patch]; +} diff --git a/test/utils/semverToArray.test.ts b/test/utils/semverToArray.test.ts deleted file mode 100644 index f3e3fc1f..00000000 --- a/test/utils/semverToArray.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expect } from "chai"; -import { semverToArray } from "../../src/utils/semverToArray.js"; - -describe("semver to array conversions", () => { - const semver = "0.1.5"; - const versionArray = ["0", "1", "5"]; - - it("should convert a semver version to array", () => { - expect(semverToArray(semver)).to.deep.equal(versionArray); - }); -}); diff --git a/test/utils/semverToArrayOfBigNumberish.test.ts b/test/utils/semverToArrayOfBigNumberish.test.ts new file mode 100644 index 00000000..cb04a82b --- /dev/null +++ b/test/utils/semverToArrayOfBigNumberish.test.ts @@ -0,0 +1,11 @@ +import { expect } from "chai"; +import { semverToArrayOfBigNumberish } from "../../src/utils/semverToArrayOfBigNumberish.js"; + +describe("semver to array conversions", () => { + const semver = "0.1.5"; + const versionArray = [0, 1, 5]; + + it("should convert a semver version to array", () => { + expect(semverToArrayOfBigNumberish(semver)).to.deep.equal(versionArray); + }); +});