From 515581fa8c6c9ac3913e9be6cd3c75248bf761bc Mon Sep 17 00:00:00 2001 From: Zane Starr Date: Wed, 27 Sep 2023 23:36:09 -0700 Subject: [PATCH] fix: resolve translation between solidity and javascript issues --- contracts/TinyHops.sol | 21 +- example.thops.json | 15 +- hardhat-scripts/deploy.ts | 16 + hardhat.config.ts | 6 + package-lock.json | 232 +++++++-- package.json | 10 +- schema.json | 25 +- scripts/encoding.js | 8 + scripts/generate.js | 22 + scripts/harness.ts | 18 + src/cli/index.ts | 21 +- src/commands/index.ts | 1 + src/commands/monitor.ts | 88 ++++ src/commands/start.ts | 47 ++ src/config.ts | 23 + .../typechain-types/CustomModicum.ts | 181 +++++++ .../TinyHops.sol/ModicumContract.ts | 96 ++++ .../typechain-types/TinyHops.sol/TinyHops.ts | 483 +++++++++++++++++ .../typechain-types/TinyHops.sol/index.ts | 5 + .../factories/CustomModicum__factory.ts | 188 +++++++ .../TinyHops.sol/ModicumContract__factory.ts | 49 ++ .../TinyHops.sol/TinyHops__factory.ts | 491 ++++++++++++++++++ .../factories/TinyHops.sol/index.ts | 5 + .../typechain-types/factories/index.ts | 4 +- .../LibTinyHopsTemplateResolver__factory.ts | 86 +++ .../factories/library/index.ts | 4 + src/generated/typechain-types/hardhat.d.ts | 18 + src/generated/typechain-types/index.ts | 12 +- .../library/LibTinyHopsTemplateResolver.ts | 94 ++++ .../typechain-types/library/index.ts | 4 + src/generated/workflow_schema.ts | 21 + src/lib/index.ts | 119 +++++ test/foundry/TinyHops.t.sol | 8 + tsconfig.json | 2 +- 34 files changed, 2341 insertions(+), 82 deletions(-) create mode 100644 hardhat-scripts/deploy.ts create mode 100644 scripts/encoding.js create mode 100644 scripts/generate.js create mode 100644 scripts/harness.ts create mode 100644 src/commands/index.ts create mode 100644 src/commands/monitor.ts create mode 100644 src/commands/start.ts create mode 100644 src/config.ts create mode 100644 src/generated/typechain-types/CustomModicum.ts create mode 100644 src/generated/typechain-types/TinyHops.sol/ModicumContract.ts create mode 100644 src/generated/typechain-types/TinyHops.sol/TinyHops.ts create mode 100644 src/generated/typechain-types/TinyHops.sol/index.ts create mode 100644 src/generated/typechain-types/factories/CustomModicum__factory.ts create mode 100644 src/generated/typechain-types/factories/TinyHops.sol/ModicumContract__factory.ts create mode 100644 src/generated/typechain-types/factories/TinyHops.sol/TinyHops__factory.ts create mode 100644 src/generated/typechain-types/factories/TinyHops.sol/index.ts create mode 100644 src/generated/typechain-types/factories/library/LibTinyHopsTemplateResolver__factory.ts create mode 100644 src/generated/typechain-types/factories/library/index.ts create mode 100644 src/generated/typechain-types/library/LibTinyHopsTemplateResolver.ts create mode 100644 src/generated/typechain-types/library/index.ts create mode 100644 src/generated/workflow_schema.ts create mode 100644 src/lib/index.ts diff --git a/contracts/TinyHops.sol b/contracts/TinyHops.sol index 696995f..8322cf5 100644 --- a/contracts/TinyHops.sol +++ b/contracts/TinyHops.sol @@ -162,7 +162,7 @@ contract TinyHops { } } workflowIdToOwner[workflowIdCounter] = msg.sender; - + emit WorkflowAdded(workflowId, msg.sender); return workflowId; } @@ -312,13 +312,24 @@ contract TinyHops { uint256 workflowId, uint256 workflowIndex ) internal { + console.log("next step"); Workflow storage workflow = workflowIdToWorkflow[workflowId]; uint256 numEntries = workflow.entries[workflowIndex].length; for (uint256 i = 0; i < numEntries; i = i + 1) { // This will also throw on underflow must have non zero balance at all times updateBalance(workflowId, workflow.entries[workflowIndex][i].cost); + console.log("past cost"); + + console.log("apply variable"); + console.log( + LibTinyHopsTemplateResolver.applyVariables( + workflow.entries[workflowIndex][i].params, + workflowIdToResultCid[workflowId] + ) + ); + console.log("past apply variable"); uint256 jobId = remoteContractInstance .runModuleWithDefaultMediators{ value: workflow.entries[workflowIndex][i].cost @@ -362,11 +373,7 @@ contract TinyHops { function getWorkFlowResults( uint256 workflowId - ) - public - view - returns (uint256[] memory, string[] memory, string[] memory params) - { + ) public view returns (uint256[] memory, string[] memory, string[] memory) { Workflow storage workflow = workflowIdToWorkflow[workflowId]; uint256 numEntries = 0; for (uint256 i = 0; i < workflow.entries.length; i++) { @@ -448,6 +455,8 @@ contract TinyHops { // This must be implemented in order to receive the job results back! function receiveJobResults(uint256 _jobID, string calldata _cid) public { + console.log("jobId", _jobID); + console.log("cid", _cid); uint256 workflowId = _updateStepStatus( _jobID, _cid, diff --git a/example.thops.json b/example.thops.json index 30cd48c..c672df9 100644 --- a/example.thops.json +++ b/example.thops.json @@ -1,13 +1,15 @@ { - "$schema": "./schema.json", + "$schema": "http://json-schema.org/draft-04/schema#", + "version": "v0.0.1", "steps": [ { "stepDesc": "First cow say", "stepName": "cows say", "stepId": "1", "stepModule": { + "cost": "5", "cmd": "cowsay:v0.0.1", - "params": "{{stepName:2}} helloworld" + "params": "hello world" } }, [{ @@ -15,8 +17,9 @@ "stepName": "cows say", "stepId": "2", "stepModule": { + "cost": "5", "cmd": "cowsay:v0.0.1", - "params": "{{stepName:2}} hello parallel world {stepId:1}" + "params": "parallel job 0 hello parallel world {{stepId:1}}" } }, { @@ -24,8 +27,9 @@ "stepName": "cows say", "stepId": "3", "stepModule": { + "cost": "5", "cmd": "cowsay:v0.0.1", - "params": "{{stepName:2}} hello parallel world {stepId:1}" + "params": "parallel job 1 hello parallel world {{stepId:1}}" } }], { @@ -33,8 +37,9 @@ "stepName": "lastcowsay", "stepId": "4", "stepModule": { + "cost": "5", "cmd": "cowsay:v0.0.1", - "params": "{{stepName:4}} hello parallel world {stepId:2} {stepId:3}" + "params": "We got all the parallel {{stepId:2}}, {{stepId:3}} worlds " } } ] diff --git a/hardhat-scripts/deploy.ts b/hardhat-scripts/deploy.ts new file mode 100644 index 0000000..6bdd953 --- /dev/null +++ b/hardhat-scripts/deploy.ts @@ -0,0 +1,16 @@ +/* eslint prefer-const: "off" */ + +import "@nomicfoundation/hardhat-ethers"; + +async function main() { + const [deployer] = await ethers.getSigners(); + const tinyHops = ethers.getContractFactory("TinyHops"); + const customModicum = ethers.getContractFactory("CustomModicum"); + const contract = await ethers.deployContract("CustomModicum", { }); + await contract.waitForDeployment(); + console.log("the addr", contract.target); + const tinyHopsContract = await ethers.deployContract("TinyHops", [contract.target]); + await tinyHopsContract.waitForDeployment(); + console.log("tiny hops addr", tinyHopsContract.target); +} +main() \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index 11fd36d..c8c43ad 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -89,6 +89,12 @@ const config: HardhatUserConfig = { gas: "auto", accounts: [PRIV_KEY], chainId: 1337 + }, + lilypad2: { + url: "http://testnetv2.arewehotshityet.com:8545", + gas: "auto", + accounts: [PRIV_KEY], + chainId: 1337 } } diff --git a/package-lock.json b/package-lock.json index 6962503..19906c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,14 @@ "version": "0.0.0-development", "license": "Apache-2.0", "dependencies": { + "ajv": "^8.12.0", "chalk": "^4.0.0", "dotenv": "^16.3.1", "typescript": "^5.2.2" }, "devDependencies": { + "@json-schema-tools/dereferencer": "^1.6.1", + "@json-schema-tools/transpiler": "^1.10.3", "@nomicfoundation/hardhat-ethers": "^3.0.4", "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-toolbox": "^3.0.0", @@ -938,6 +941,72 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@json-schema-spec/json-pointer": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@json-schema-spec/json-pointer/-/json-pointer-0.1.2.tgz", + "integrity": "sha512-BYY7IavBjwsWWSmVcMz2A9mKiDD9RvacnsItgmy1xV8cmgbtxFfKmKMtkVpD7pYtkx4mIW4800yZBXueVFIWPw==", + "dev": true + }, + "node_modules/@json-schema-tools/dereferencer": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@json-schema-tools/dereferencer/-/dereferencer-1.6.1.tgz", + "integrity": "sha512-+h+K/H3pWoJVztTuz1ycTUc0ai/xH5eLZLurE4jQpqYwPcPvsXtFfbRxDhvxrrpjjg4PV3HmEjjORIEQPO4Dmw==", + "dev": true, + "dependencies": { + "@json-schema-tools/reference-resolver": "^1.2.5", + "@json-schema-tools/traverse": "^1.10.0", + "fast-safe-stringify": "^2.1.1" + } + }, + "node_modules/@json-schema-tools/reference-resolver": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@json-schema-tools/reference-resolver/-/reference-resolver-1.2.5.tgz", + "integrity": "sha512-xNQgX/ABnwvbIeexL5Czv08lXjHAL80HEUogza7E19eIL/EXD8HM4FvxG1JuTGyi5fA+sSP64C9pabELizcBBw==", + "dev": true, + "dependencies": { + "@json-schema-spec/json-pointer": "^0.1.2", + "isomorphic-fetch": "^3.0.0" + } + }, + "node_modules/@json-schema-tools/referencer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@json-schema-tools/referencer/-/referencer-1.1.0.tgz", + "integrity": "sha512-t9XTMNRhFQPFBOPkqIOGck2rMoI1wMqD8EdboZJAVR2erUHezpsxyXO6EjuH3mE4LSCOnXI2wrBspeRFtAskoQ==", + "dev": true, + "dependencies": { + "@json-schema-tools/traverse": "^1.10.1" + } + }, + "node_modules/@json-schema-tools/titleizer": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@json-schema-tools/titleizer/-/titleizer-1.0.8.tgz", + "integrity": "sha512-xgsg7ghVhd+9ZrhpmakNJUMmp+R+1mB6n4zn4iRg6P47GTfN04L/GR7mjC8LvO+XaZxbIzE6EzvHeZ5+nmhjJA==", + "dev": true, + "dependencies": { + "@json-schema-tools/traverse": "^1.10.1" + } + }, + "node_modules/@json-schema-tools/transpiler": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@json-schema-tools/transpiler/-/transpiler-1.10.3.tgz", + "integrity": "sha512-IOtTHSL9vUZA8xss7Am5NrqQopwM10VS4yjFYmZ/QaqTLx6moE7j/md0k+BhMMsKMjZul/D0GXLerZXg9HU7Mg==", + "dev": true, + "dependencies": { + "@json-schema-tools/referencer": "^1.0.6", + "@json-schema-tools/titleizer": "^1.0.8", + "@json-schema-tools/traverse": "^1.10.1", + "lodash.camelcase": "^4.3.0", + "lodash.deburr": "^4.1.0", + "lodash.snakecase": "^4.1.1", + "lodash.trim": "^4.5.1" + } + }, + "node_modules/@json-schema-tools/traverse": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@json-schema-tools/traverse/-/traverse-1.10.1.tgz", + "integrity": "sha512-vYY5EIxCPzEXEWL/vTjdHy4g92tv1ApUQCjPJsj9gEoXLNNVwJlwwgRZisuvgFBZ3zeLzQygrbehERSpYdmFZA==", + "dev": true + }, "node_modules/@metamask/eth-sig-util": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@metamask/eth-sig-util/-/eth-sig-util-4.0.1.tgz", @@ -2507,15 +2576,13 @@ } }, "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "peer": true, + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", + "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", "dependencies": { "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", "uri-js": "^4.2.2" }, "funding": { @@ -4913,9 +4980,7 @@ "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true, - "peer": true + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "node_modules/fast-glob": { "version": "3.3.1", @@ -4948,6 +5013,12 @@ "dev": true, "peer": true }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "dev": true + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -5434,6 +5505,30 @@ "node": ">=6" } }, + "node_modules/har-validator/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "peer": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/har-validator/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "peer": true + }, "node_modules/hardhat": { "version": "2.17.3", "resolved": "https://registry.npmjs.org/hardhat/-/hardhat-2.17.3.tgz", @@ -6251,6 +6346,16 @@ "dev": true, "peer": true }, + "node_modules/isomorphic-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", + "dev": true, + "dependencies": { + "node-fetch": "^2.6.1", + "whatwg-fetch": "^3.4.1" + } + }, "node_modules/isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -6304,11 +6409,9 @@ "peer": true }, "node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true, - "peer": true + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, "node_modules/json-stringify-safe": { "version": "5.0.1", @@ -6469,8 +6572,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==", - "dev": true, - "peer": true + "dev": true }, "node_modules/lodash.clonedeep": { "version": "4.5.0", @@ -6479,12 +6581,30 @@ "dev": true, "peer": true }, + "node_modules/lodash.deburr": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/lodash.deburr/-/lodash.deburr-4.1.0.tgz", + "integrity": "sha512-m/M1U1f3ddMCs6Hq2tAsYThTBDaAKFDX3dwDo97GEYzamXi9SqUpjWi/Rrj/gf3X2n8ktwgZrlP1z6E3v/IExQ==", + "dev": true + }, "node_modules/lodash.isequal": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", "dev": true }, + "node_modules/lodash.snakecase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", + "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==", + "dev": true + }, + "node_modules/lodash.trim": { + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/lodash.trim/-/lodash.trim-4.5.1.tgz", + "integrity": "sha512-nJAlRl/K+eiOehWKDzoBVrSMhK0K3A3YQsUNXHQa5yIrKBAhsZgSu3KoAFoFT+mEgiyBHddZ0pRk1ITpIp90Wg==", + "dev": true + }, "node_modules/lodash.truncate": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.truncate/-/lodash.truncate-4.4.2.tgz", @@ -6986,6 +7106,26 @@ "semver": "bin/semver" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dev": true, + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-gyp-build": { "version": "4.6.1", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.1.tgz", @@ -7388,8 +7528,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", - "dev": true, - "peer": true, "engines": { "node": ">=6" } @@ -7652,8 +7790,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "dev": true, - "peer": true, "engines": { "node": ">=0.10.0" } @@ -8695,30 +8831,6 @@ "node": ">=8" } }, - "node_modules/table/node_modules/ajv": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", - "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", - "dev": true, - "peer": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/table/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, - "peer": true - }, "node_modules/then-request": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/then-request/-/then-request-6.0.2.tgz", @@ -8799,6 +8911,12 @@ "node": ">=0.8" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "dev": true + }, "node_modules/ts-command-line-args": { "version": "2.5.1", "resolved": "https://registry.npmjs.org/ts-command-line-args/-/ts-command-line-args-2.5.1.tgz", @@ -9163,8 +9281,6 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", - "dev": true, - "peer": true, "dependencies": { "punycode": "^2.1.0" } @@ -9289,6 +9405,28 @@ "@scure/bip39": "1.2.1" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "dev": true + }, + "node_modules/whatwg-fetch": { + "version": "3.6.19", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.19.tgz", + "integrity": "sha512-d67JP4dHSbm2TrpFj8AbO8DnL1JXL5J9u0Kq2xW6d0TFDbCA3Muhdt8orXC22utleTVj7Prqt82baN6RBvnEgw==", + "dev": true + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dev": true, + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 8d6452e..7b18e03 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,20 @@ "test": "test" }, "scripts": { - "compile": "tsc", + "start": "node build/src/cli/index.js", + "build": "tsc", + "gen-types": "node scripts/generate.js", "compile-contracts": "npx hardhat compile", + "deploy-local": "npx hardhat run hardhat-scripts/deploy.ts --network localhost", + "deploy-testnet": "npx hardhat run hardhat-scripts/deploy.ts --network lilypad", + "deploy-testnet2": "npx hardhat run hardhat-scripts/deploy.ts --network lilypad2", "test": "forge test" }, "author": "", "license": "Apache-2.0", "devDependencies": { + "@json-schema-tools/dereferencer": "^1.6.1", + "@json-schema-tools/transpiler": "^1.10.3", "@nomicfoundation/hardhat-ethers": "^3.0.4", "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-toolbox": "^3.0.0", @@ -25,6 +32,7 @@ "ts-node": "^10.9.1" }, "dependencies": { + "ajv": "^8.12.0", "chalk": "^4.0.0", "dotenv": "^16.3.1", "typescript": "^5.2.2" diff --git a/schema.json b/schema.json index d99b61a..28fe3b1 100644 --- a/schema.json +++ b/schema.json @@ -1,6 +1,5 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "https://tiny-hops-workflow-schema", + "$id": "https://tiny-hops-workflow-schema", "title": "workflow", "$ref": "#/definitions/workflow", "definitions": { @@ -9,6 +8,7 @@ "type": "string" }, "workflow": { + "title": "workflow", "type": "object", "properties": { "version": { @@ -21,6 +21,7 @@ "required": ["version", "steps"] }, "steps": { + "title": "steps", "type": "array", "items": { "oneOf": [ @@ -34,6 +35,7 @@ } }, "stepModule": { + "title":"stepModule", "cmd": { "title": "cmd", "type": "string" @@ -42,7 +44,11 @@ "title": "params", "type": "string" }, - "required": ["cmd","params"] + "cost": { + "$ref":"#/definitions/cost" + }, + "required": ["cmd","params", "cost"], + "additionalItems": false }, "stepItem": { "title": "stepItem", @@ -62,14 +68,20 @@ } }, "additionalItems": false, - "required": ["stepInput", "stepId"] + "required": ["stepModule", "stepId"] }, "stepItems": { + "title": "stepItems", "type": "array", "items": { "$ref": "#/definitions/stepItem" } }, + "cost": { + "title": "cost", + "type": "string", + "pattern": "^[0-9]+[.][0-9]+$" + }, "stepId": { "title": "stepId", "type": "string" @@ -83,6 +95,7 @@ "type": "string" }, "inputFormatStepId": { + "title": "inputFormatStepId", "type": "object", "properties": { "stepId": { @@ -92,6 +105,7 @@ "additionalProperties": false }, "inputFormatCid": { + "title": "inputFormatCid", "type": "object", "properties": { "cid": { @@ -101,6 +115,7 @@ "additionalProperties": false }, "inputFormatUri": { + "title": "inputFormatUri", "type": "object", "properties": { "uri": { @@ -112,6 +127,7 @@ "additionalProperties": false }, "inputFormatMetadata": { + "title": "inputFormatMetadata", "oneOf": [ { "$ref": "#/definitions/inputFormatCid" @@ -125,6 +141,7 @@ ] }, "inputFormat": { + "title": "inputFormat", "type": "array", "items": { "$ref": "#/definitions/inputFormatMetadata" diff --git a/scripts/encoding.js b/scripts/encoding.js new file mode 100644 index 0000000..3388aa0 --- /dev/null +++ b/scripts/encoding.js @@ -0,0 +1,8 @@ +import {stringToByteStream} from "../src/lib/index" +const str = "hello world {{stepId:1}}"; +const params = stringToByteStream(str); + +console.log("string",) +console.log("bytes",params) +console.log("hex", Buffer.from(params).toString("hex")) +console.log("hex 0000000000000000000c68656c6c6f20776f726c642000010000000000000001") diff --git a/scripts/generate.js b/scripts/generate.js new file mode 100644 index 0000000..4721d5d --- /dev/null +++ b/scripts/generate.js @@ -0,0 +1,22 @@ +const JsonSchemaTranspiler = require('@json-schema-tools/transpiler').default; +const metadataConfigSchema = require('../schema.json'); +const Dereferencer = require('@json-schema-tools/dereferencer').default; +const fs = require('fs-extra'); + +async function generate(fileName, schema) { + const dereffer = new Dereferencer(schema); + const dereffedSchema = await dereffer.resolve(); + const transpiler = new JsonSchemaTranspiler(dereffedSchema); + fs.writeFile(fileName, transpiler.toTypescript()); +} +(async function () { + try { + console.log('made it started'); + await generate( + './src/generated/workflow_schema.ts', + metadataConfigSchema, + ); + } catch (e) { + console.log(e); + } +})(); diff --git a/scripts/harness.ts b/scripts/harness.ts new file mode 100644 index 0000000..e535cdf --- /dev/null +++ b/scripts/harness.ts @@ -0,0 +1,18 @@ +import {stringToByteStream} from "../src/lib/" +import * as config from "../build/src/config"; +import { CustomModicum__factory } from "../build/src/generated/typechain-types"; +import { TinyHops__factory } from "../build/src/generated/typechain-types"; + +const workflowId = 2; +const main = async () => { +const modicum = CustomModicum__factory.connect(config.MODICUM_MOCK_ADDR,config.getWallet()); +const tinyHops = TinyHops__factory.connect(config.TINY_HOPS_CONTRACT_ADDR, config.getWallet()); +const jobs = await modicum.getCurrentJobs(); +await tinyHops.receiveJobResults(jobs[0],"dummycid") +console.log(await tinyHops.getWorkFlowResults(workflowId)); +console.log(jobs); +} + +main(); + + diff --git a/src/cli/index.ts b/src/cli/index.ts index b2090b9..205e691 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,5 +1,8 @@ import { Command } from 'commander'; import chalk from 'chalk'; +import { convertThopsToWorkflow } from '../lib'; +import { startWorkflowCmd } from '../commands'; +import { workflowStatus } from '../commands/monitor'; const program = new Command(); @@ -21,22 +24,16 @@ program .description('Run a workflow with a specified configuration file') .action((config, options) => { console.log(chalk.green(`Running workflow with config: ${chalk.cyan(config)} and deposit: ${chalk.yellow(options.deposit)}`)); - // Implementation here... + startWorkflowCmd(config, options.deposit); + // Implementation here... }); program - .command('monitor ') - .description('Monitor a running workflow') + .command('status ') + .description('See the status of a workflow') .action((workflowId, config) => { - console.log(chalk.green(`Monitoring workflow: ${chalk.cyan(workflowId)} with config: ${chalk.cyan(config)}`)); - // Implementation here... - }); - -program - .command('pause ') - .description('Pause a running workflow') - .action((workflowId) => { - console.log(chalk.green(`Pausing workflow: ${chalk.cyan(workflowId)}`)); + console.log(chalk.green(`Displaying workflow status: ${chalk.cyan(workflowId)} with config: ${chalk.cyan(config)}`)); + workflowStatus(workflowId, config) // Implementation here... }); diff --git a/src/commands/index.ts b/src/commands/index.ts new file mode 100644 index 0000000..da59d9a --- /dev/null +++ b/src/commands/index.ts @@ -0,0 +1 @@ +export { startWorkflowCmd } from "./start"; diff --git a/src/commands/monitor.ts b/src/commands/monitor.ts new file mode 100644 index 0000000..637ecb2 --- /dev/null +++ b/src/commands/monitor.ts @@ -0,0 +1,88 @@ +import { TinyHops__factory } from "../generated/typechain-types"; +import * as config from "../config"; +import fs from "fs"; +import ajv from "ajv"; +import path from "path"; +import { Workflow } from "../generated/workflow_schema"; +import thopsSchema from "../../schema.json"; +interface WorkflowMetadata { + stepName: string; + stepDesc: string; + stepCmd: string; +} + +interface ResultMeta { + resultId: string; + params: string; +} +export const workflowStatus = async ( + workflowId: string, + configPath: string +) => { + const tinyHops = TinyHops__factory.connect( + config.getTinyHopAddr(), + config.getWallet() + ); + const data = JSON.parse(fs.readFileSync(path.resolve(configPath), "utf-8")); + const validator = new ajv({ strict: false }); + const validate = validator.compile(thopsSchema); + const result = validate(data); + if (result === false) { + throw new Error("Schema Invalid" + validator.errorsText(validate.errors)); + } + const workflow = data as Workflow; + + + const results = await tinyHops.getWorkFlowResults(workflowId); + const [stepIds, cidResults, parameters] = results; + const resultMap: any = {} + stepIds.forEach((stepId: bigint, index: number) => { + resultMap[stepId.toString()] = { + resultId: cidResults[index], + params: parameters[index] + } + }) + + const workflowMetdataMap:any = {}; + workflow.steps.forEach((stepGroup)=> { + if(Array.isArray(stepGroup)){ + stepGroup.forEach((step)=> { + workflowMetdataMap[step.stepId] = { + stepName: step.stepName, + stepDesc: step.stepDesc, + stepCmd: step.stepModule.cmd, + stepResult: resultMap[step.stepId] + } + }); + + }else{ + workflowMetdataMap[stepGroup.stepId] = { + stepName: stepGroup.stepName, + stepDesc : stepGroup.stepDesc, + stepCmd: stepGroup.stepModule.cmd, + stepResult: resultMap[stepGroup.stepId] + } + } + }) + + console.log("workflow is currenty:", await getStatusText(workflowId)); + console.log(JSON.stringify(workflowMetdataMap, null, 2)); + +}; +async function getStatusText(workflowId: string): Promise { + const tinyHops = TinyHops__factory.connect( + config.getTinyHopAddr(), + config.getWallet() + ); + const status = await tinyHops.getWorkFlowStatus(workflowId); + switch(status.toString()){ + case "0": + return "Pending"; + case "1": + return "Running"; + case "2": + return "Completed"; + default: + return "Unknown"; + } +} diff --git a/src/commands/start.ts b/src/commands/start.ts new file mode 100644 index 0000000..7a62b5e --- /dev/null +++ b/src/commands/start.ts @@ -0,0 +1,47 @@ +import { TinyHops, TinyHops__factory } from "../generated/typechain-types"; +import { WorkflowAddedEvent } from "../generated/typechain-types/TinyHops.sol/TinyHops"; + +import * as config from "../config" +import { convertThopsToWorkflow } from "../lib"; +import { EventLog, ethers } from "ethers"; + + +export const startWorkflowCmd = async (configPath: string, deposit: number) => { + + const workflow = convertThopsToWorkflow(configPath); + + const tinyHops = TinyHops__factory.connect(config.getTinyHopAddr(), config.getWallet()) + console.log(await config.getWallet().provider?.getBlockNumber()); + console.log(await tinyHops.getBalance(0)) + workflow.entries.map(console.log) + console.log("storing workflow...."); + const tx = await tinyHops.storeWorkflow(workflow); + try{ + const workflowId = await parseWorkflowAddedEventFromTx(tx); + console.log("stored worfklow with id:", workflowId); + console.log(`starting workflow with id ${workflowId}, and ${deposit} eth`); + const txStart = await tinyHops.startWorkflow(workflowId, {value: ethers.parseEther(deposit.toString())}) + await txStart.wait(); + console.log("workflow started") + }catch(e){ + console.log("error", e); + } + +} + + + + + +const parseWorkflowAddedEventFromTx = async (tx: ethers.ContractTransactionResponse): Promise => { + const receipt = await tx.wait(); + const logs = receipt?.logs; + const iface = new ethers.Interface([ + "event WorkflowAdded(uint256 workflowId, address owner)" + ]); + const parsedLogs = logs?.map(log => iface.parseLog(log as any)); + const workflowAddedEvent = parsedLogs?.find(log => (log as any).name === "WorkflowAdded") as any; + console.log("WorkflowAdded event:", workflowAddedEvent); + return workflowAddedEvent.args[0].toString() +}; + diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..4ce8ce1 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,23 @@ +import {ethers} from "ethers" +import process from "process" + +export const TINY_HOPS_CONTRACT_ADDR= +"0x9363298F37f1B285f25Add8317137DfC087de369" +export const MODICUM_MOCK_ADDR = +//"0x9A676e781A523b5d0C0e43731313A708CB607508" +"0x5FbDB2315678afecb367f032d93F642f64180aa3" + +const THOPS_RPC_URL = //"http://testnet.lilypadnetwork.org:8545" +"http://testnetv2.arewehotshityet.com:8545" + +export const getPrivateKey = () => { + return process.env.THOPS_PRIVATE_KEY || "" +} + +export const getWallet=()=> { + return new ethers.Wallet(getPrivateKey(), + new ethers.JsonRpcProvider(THOPS_RPC_URL || "http://127.0.0.1:8545")) +} +export const getTinyHopAddr=() => { + return TINY_HOPS_CONTRACT_ADDR +} \ No newline at end of file diff --git a/src/generated/typechain-types/CustomModicum.ts b/src/generated/typechain-types/CustomModicum.ts new file mode 100644 index 0000000..5560d86 --- /dev/null +++ b/src/generated/typechain-types/CustomModicum.ts @@ -0,0 +1,181 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumberish, + BytesLike, + FunctionFragment, + Result, + Interface, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedListener, + TypedContractMethod, +} from "./common"; + +export interface CustomModicumInterface extends Interface { + getFunction( + nameOrSignature: + | "clearJobIds" + | "currentJobs" + | "getBalance" + | "getCurrentJobs" + | "getJobId" + | "getParams" + | "runModuleWithDefaultMediators" + ): FunctionFragment; + + encodeFunctionData( + functionFragment: "clearJobIds", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "currentJobs", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getBalance", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getCurrentJobs", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getJobId", + values: [string, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getParams", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "runModuleWithDefaultMediators", + values: [string, string] + ): string; + + decodeFunctionResult( + functionFragment: "clearJobIds", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "currentJobs", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getBalance", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getCurrentJobs", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getJobId", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "getParams", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "runModuleWithDefaultMediators", + data: BytesLike + ): Result; +} + +export interface CustomModicum extends BaseContract { + connect(runner?: ContractRunner | null): CustomModicum; + waitForDeployment(): Promise; + + interface: CustomModicumInterface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + clearJobIds: TypedContractMethod<[], [void], "nonpayable">; + + currentJobs: TypedContractMethod<[arg0: BigNumberish], [bigint], "view">; + + getBalance: TypedContractMethod<[], [bigint], "view">; + + getCurrentJobs: TypedContractMethod<[], [bigint[]], "view">; + + getJobId: TypedContractMethod< + [name: string, params: string, jobNo: BigNumberish], + [bigint], + "view" + >; + + getParams: TypedContractMethod<[jobId: BigNumberish], [string], "view">; + + runModuleWithDefaultMediators: TypedContractMethod< + [name: string, params: string], + [bigint], + "payable" + >; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "clearJobIds" + ): TypedContractMethod<[], [void], "nonpayable">; + getFunction( + nameOrSignature: "currentJobs" + ): TypedContractMethod<[arg0: BigNumberish], [bigint], "view">; + getFunction( + nameOrSignature: "getBalance" + ): TypedContractMethod<[], [bigint], "view">; + getFunction( + nameOrSignature: "getCurrentJobs" + ): TypedContractMethod<[], [bigint[]], "view">; + getFunction( + nameOrSignature: "getJobId" + ): TypedContractMethod< + [name: string, params: string, jobNo: BigNumberish], + [bigint], + "view" + >; + getFunction( + nameOrSignature: "getParams" + ): TypedContractMethod<[jobId: BigNumberish], [string], "view">; + getFunction( + nameOrSignature: "runModuleWithDefaultMediators" + ): TypedContractMethod<[name: string, params: string], [bigint], "payable">; + + filters: {}; +} diff --git a/src/generated/typechain-types/TinyHops.sol/ModicumContract.ts b/src/generated/typechain-types/TinyHops.sol/ModicumContract.ts new file mode 100644 index 0000000..50be921 --- /dev/null +++ b/src/generated/typechain-types/TinyHops.sol/ModicumContract.ts @@ -0,0 +1,96 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BytesLike, + FunctionFragment, + Result, + Interface, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedListener, + TypedContractMethod, +} from "../common"; + +export interface ModicumContractInterface extends Interface { + getFunction( + nameOrSignature: "runModuleWithDefaultMediators" + ): FunctionFragment; + + encodeFunctionData( + functionFragment: "runModuleWithDefaultMediators", + values: [string, string] + ): string; + + decodeFunctionResult( + functionFragment: "runModuleWithDefaultMediators", + data: BytesLike + ): Result; +} + +export interface ModicumContract extends BaseContract { + connect(runner?: ContractRunner | null): ModicumContract; + waitForDeployment(): Promise; + + interface: ModicumContractInterface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + runModuleWithDefaultMediators: TypedContractMethod< + [name: string, params: string], + [bigint], + "payable" + >; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "runModuleWithDefaultMediators" + ): TypedContractMethod<[name: string, params: string], [bigint], "payable">; + + filters: {}; +} diff --git a/src/generated/typechain-types/TinyHops.sol/TinyHops.ts b/src/generated/typechain-types/TinyHops.sol/TinyHops.ts new file mode 100644 index 0000000..4d7eb96 --- /dev/null +++ b/src/generated/typechain-types/TinyHops.sol/TinyHops.ts @@ -0,0 +1,483 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumberish, + BytesLike, + FunctionFragment, + Result, + Interface, + EventFragment, + AddressLike, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedLogDescription, + TypedListener, + TypedContractMethod, +} from "../common"; + +export type WorkflowEntryStruct = { + cost: BigNumberish; + stepId: BigNumberish; + cmd: string; + params: BytesLike; +}; + +export type WorkflowEntryStructOutput = [ + cost: bigint, + stepId: bigint, + cmd: string, + params: string +] & { cost: bigint; stepId: bigint; cmd: string; params: string }; + +export type WorkflowStruct = { entries: WorkflowEntryStruct[][] }; + +export type WorkflowStructOutput = [entries: WorkflowEntryStructOutput[][]] & { + entries: WorkflowEntryStructOutput[][]; +}; + +export interface TinyHopsInterface extends Interface { + getFunction( + nameOrSignature: + | "checkAllEntryStepsComplete" + | "checkPreviousLevelComplete" + | "contractAddress" + | "getBalance" + | "getStepStatus" + | "getWorkFlowResults" + | "getWorkFlowStatus" + | "getWorkHash" + | "job1" + | "job2" + | "ownerOf" + | "receiveJobResults" + | "resultCIDs1" + | "resultCIDs2" + | "resultJobId1" + | "resultJobId2" + | "startWorkflow" + | "storeWorkflow" + | "workflowIdCounter" + ): FunctionFragment; + + getEvent( + nameOrSignatureOrTopic: "WorkflowAdded" | "WorkflowStartedJob" + ): EventFragment; + + encodeFunctionData( + functionFragment: "checkAllEntryStepsComplete", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "checkPreviousLevelComplete", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "contractAddress", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getBalance", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getStepStatus", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getWorkFlowResults", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getWorkFlowStatus", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getWorkHash", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "job1", values?: undefined): string; + encodeFunctionData(functionFragment: "job2", values?: undefined): string; + encodeFunctionData( + functionFragment: "ownerOf", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "receiveJobResults", + values: [BigNumberish, string] + ): string; + encodeFunctionData( + functionFragment: "resultCIDs1", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "resultCIDs2", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "resultJobId1", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "resultJobId2", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "startWorkflow", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "storeWorkflow", + values: [WorkflowStruct] + ): string; + encodeFunctionData( + functionFragment: "workflowIdCounter", + values?: undefined + ): string; + + decodeFunctionResult( + functionFragment: "checkAllEntryStepsComplete", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "checkPreviousLevelComplete", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "contractAddress", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getBalance", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getStepStatus", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getWorkFlowResults", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getWorkFlowStatus", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getWorkHash", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "job1", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "job2", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "ownerOf", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "receiveJobResults", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "resultCIDs1", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "resultCIDs2", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "resultJobId1", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "resultJobId2", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "startWorkflow", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "storeWorkflow", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "workflowIdCounter", + data: BytesLike + ): Result; +} + +export namespace WorkflowAddedEvent { + export type InputTuple = [workflowId: BigNumberish, owner: AddressLike]; + export type OutputTuple = [workflowId: bigint, owner: string]; + export interface OutputObject { + workflowId: bigint; + owner: string; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export namespace WorkflowStartedJobEvent { + export type InputTuple = [ + workflowId: BigNumberish, + jobId: BigNumberish, + balance: BigNumberish + ]; + export type OutputTuple = [ + workflowId: bigint, + jobId: bigint, + balance: bigint + ]; + export interface OutputObject { + workflowId: bigint; + jobId: bigint; + balance: bigint; + } + export type Event = TypedContractEvent; + export type Filter = TypedDeferredTopicFilter; + export type Log = TypedEventLog; + export type LogDescription = TypedLogDescription; +} + +export interface TinyHops extends BaseContract { + connect(runner?: ContractRunner | null): TinyHops; + waitForDeployment(): Promise; + + interface: TinyHopsInterface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + checkAllEntryStepsComplete: TypedContractMethod< + [_workflowId: BigNumberish], + [boolean], + "view" + >; + + checkPreviousLevelComplete: TypedContractMethod< + [workflowID: BigNumberish, workflowIndex: BigNumberish], + [boolean], + "nonpayable" + >; + + contractAddress: TypedContractMethod<[], [string], "view">; + + getBalance: TypedContractMethod<[workflowId: BigNumberish], [bigint], "view">; + + getStepStatus: TypedContractMethod< + [workflowId: BigNumberish, stepId: BigNumberish], + [bigint], + "view" + >; + + getWorkFlowResults: TypedContractMethod< + [workflowId: BigNumberish], + [[bigint[], string[], string[]]], + "view" + >; + + getWorkFlowStatus: TypedContractMethod< + [workflowId: BigNumberish], + [bigint], + "view" + >; + + getWorkHash: TypedContractMethod< + [_workflowId: BigNumberish, _stepId: BigNumberish], + [string], + "view" + >; + + job1: TypedContractMethod<[], [bigint], "view">; + + job2: TypedContractMethod<[], [bigint], "view">; + + ownerOf: TypedContractMethod<[workflowId: BigNumberish], [string], "view">; + + receiveJobResults: TypedContractMethod< + [_jobID: BigNumberish, _cid: string], + [void], + "nonpayable" + >; + + resultCIDs1: TypedContractMethod<[], [string], "view">; + + resultCIDs2: TypedContractMethod<[], [string], "view">; + + resultJobId1: TypedContractMethod<[], [bigint], "view">; + + resultJobId2: TypedContractMethod<[], [bigint], "view">; + + startWorkflow: TypedContractMethod< + [workflowId: BigNumberish], + [bigint], + "payable" + >; + + storeWorkflow: TypedContractMethod< + [workflow: WorkflowStruct], + [bigint], + "nonpayable" + >; + + workflowIdCounter: TypedContractMethod<[], [bigint], "view">; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "checkAllEntryStepsComplete" + ): TypedContractMethod<[_workflowId: BigNumberish], [boolean], "view">; + getFunction( + nameOrSignature: "checkPreviousLevelComplete" + ): TypedContractMethod< + [workflowID: BigNumberish, workflowIndex: BigNumberish], + [boolean], + "nonpayable" + >; + getFunction( + nameOrSignature: "contractAddress" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "getBalance" + ): TypedContractMethod<[workflowId: BigNumberish], [bigint], "view">; + getFunction( + nameOrSignature: "getStepStatus" + ): TypedContractMethod< + [workflowId: BigNumberish, stepId: BigNumberish], + [bigint], + "view" + >; + getFunction( + nameOrSignature: "getWorkFlowResults" + ): TypedContractMethod< + [workflowId: BigNumberish], + [[bigint[], string[], string[]]], + "view" + >; + getFunction( + nameOrSignature: "getWorkFlowStatus" + ): TypedContractMethod<[workflowId: BigNumberish], [bigint], "view">; + getFunction( + nameOrSignature: "getWorkHash" + ): TypedContractMethod< + [_workflowId: BigNumberish, _stepId: BigNumberish], + [string], + "view" + >; + getFunction( + nameOrSignature: "job1" + ): TypedContractMethod<[], [bigint], "view">; + getFunction( + nameOrSignature: "job2" + ): TypedContractMethod<[], [bigint], "view">; + getFunction( + nameOrSignature: "ownerOf" + ): TypedContractMethod<[workflowId: BigNumberish], [string], "view">; + getFunction( + nameOrSignature: "receiveJobResults" + ): TypedContractMethod< + [_jobID: BigNumberish, _cid: string], + [void], + "nonpayable" + >; + getFunction( + nameOrSignature: "resultCIDs1" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "resultCIDs2" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "resultJobId1" + ): TypedContractMethod<[], [bigint], "view">; + getFunction( + nameOrSignature: "resultJobId2" + ): TypedContractMethod<[], [bigint], "view">; + getFunction( + nameOrSignature: "startWorkflow" + ): TypedContractMethod<[workflowId: BigNumberish], [bigint], "payable">; + getFunction( + nameOrSignature: "storeWorkflow" + ): TypedContractMethod<[workflow: WorkflowStruct], [bigint], "nonpayable">; + getFunction( + nameOrSignature: "workflowIdCounter" + ): TypedContractMethod<[], [bigint], "view">; + + getEvent( + key: "WorkflowAdded" + ): TypedContractEvent< + WorkflowAddedEvent.InputTuple, + WorkflowAddedEvent.OutputTuple, + WorkflowAddedEvent.OutputObject + >; + getEvent( + key: "WorkflowStartedJob" + ): TypedContractEvent< + WorkflowStartedJobEvent.InputTuple, + WorkflowStartedJobEvent.OutputTuple, + WorkflowStartedJobEvent.OutputObject + >; + + filters: { + "WorkflowAdded(uint256,address)": TypedContractEvent< + WorkflowAddedEvent.InputTuple, + WorkflowAddedEvent.OutputTuple, + WorkflowAddedEvent.OutputObject + >; + WorkflowAdded: TypedContractEvent< + WorkflowAddedEvent.InputTuple, + WorkflowAddedEvent.OutputTuple, + WorkflowAddedEvent.OutputObject + >; + + "WorkflowStartedJob(uint256,uint256,uint256)": TypedContractEvent< + WorkflowStartedJobEvent.InputTuple, + WorkflowStartedJobEvent.OutputTuple, + WorkflowStartedJobEvent.OutputObject + >; + WorkflowStartedJob: TypedContractEvent< + WorkflowStartedJobEvent.InputTuple, + WorkflowStartedJobEvent.OutputTuple, + WorkflowStartedJobEvent.OutputObject + >; + }; +} diff --git a/src/generated/typechain-types/TinyHops.sol/index.ts b/src/generated/typechain-types/TinyHops.sol/index.ts new file mode 100644 index 0000000..81513b7 --- /dev/null +++ b/src/generated/typechain-types/TinyHops.sol/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { ModicumContract } from "./ModicumContract"; +export type { TinyHops } from "./TinyHops"; diff --git a/src/generated/typechain-types/factories/CustomModicum__factory.ts b/src/generated/typechain-types/factories/CustomModicum__factory.ts new file mode 100644 index 0000000..e608195 --- /dev/null +++ b/src/generated/typechain-types/factories/CustomModicum__factory.ts @@ -0,0 +1,188 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../common"; +import type { CustomModicum, CustomModicumInterface } from "../CustomModicum"; + +const _abi = [ + { + inputs: [], + name: "clearJobIds", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + name: "currentJobs", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getBalance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getCurrentJobs", + outputs: [ + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "params", + type: "string", + }, + { + internalType: "uint256", + name: "jobNo", + type: "uint256", + }, + ], + name: "getJobId", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "pure", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "jobId", + type: "uint256", + }, + ], + name: "getParams", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "params", + type: "string", + }, + ], + name: "runModuleWithDefaultMediators", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, +] as const; + +const _bytecode = + "0x608060405234801561001057600080fd5b5061078a806100206000396000f3fe6080604052600436106100705760003560e01c80637ce7b1791161004e5780637ce7b179146100df57806382677451146100f2578063da76995014610112578063ddaa0b361461013457600080fd5b806308a4f0721461007557806312065fe0146100ab5780632a81f109146100c8575b600080fd5b34801561008157600080fd5b506100956100903660046103cf565b610154565b6040516100a291906103e8565b60405180910390f35b3480156100b757600080fd5b50475b6040519081526020016100a2565b3480156100d457600080fd5b506100dd6101f6565b005b6100ba6100ed366004610486565b61023f565b3480156100fe57600080fd5b506100ba61010d3660046103cf565b6102ac565b34801561011e57600080fd5b506101276102cd565b6040516100a291906104f2565b34801561014057600080fd5b506100ba61014f366004610536565b610325565b6000818152600160205260409020805460609190610171906105aa565b80601f016020809104026020016040519081016040528092919081815260200182805461019d906105aa565b80156101ea5780601f106101bf576101008083540402835291602001916101ea565b820191906000526020600020905b8154815290600101906020018083116101cd57829003601f168201915b50505050509050919050565b60008054905b8181101561022d57600081815260016020526040812061021b91610362565b80610225816105e4565b9150506101fc565b506000905061023c818061039c565b50565b60008061025486868686600080549050610325565b6000818152600160205260409020909150610270848683610670565b50600080546001810182559080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5630181905595945050505050565b600081815481106102bc57600080fd5b600091825260209091200154905081565b6060600080548060200260200160405190810160405280929190818152602001828054801561031b57602002820191906000526020600020905b815481526020019060010190808311610307575b5050505050905090565b60008585858585604051602001610340959493929190610731565b60408051601f1981840301815291905280516020909101209695505050505050565b50805461036e906105aa565b6000825580601f1061037e575050565b601f01602090049060005260206000209081019061023c91906103b6565b508054600082559060005260206000209081019061023c91905b5b808211156103cb57600081556001016103b7565b5090565b6000602082840312156103e157600080fd5b5035919050565b600060208083528351808285015260005b81811015610415578581018301518582016040015282016103f9565b81811115610427576000604083870101525b50601f01601f1916929092016040019392505050565b60008083601f84011261044f57600080fd5b50813567ffffffffffffffff81111561046757600080fd5b60208301915083602082850101111561047f57600080fd5b9250929050565b6000806000806040858703121561049c57600080fd5b843567ffffffffffffffff808211156104b457600080fd5b6104c08883890161043d565b909650945060208701359150808211156104d957600080fd5b506104e68782880161043d565b95989497509550505050565b6020808252825182820181905260009190848201906040850190845b8181101561052a5783518352928401929184019160010161050e565b50909695505050505050565b60008060008060006060868803121561054e57600080fd5b853567ffffffffffffffff8082111561056657600080fd5b61057289838a0161043d565b9097509550602088013591508082111561058b57600080fd5b506105988882890161043d565b96999598509660400135949350505050565b600181811c908216806105be57607f821691505b6020821081036105de57634e487b7160e01b600052602260045260246000fd5b50919050565b60006001820161060457634e487b7160e01b600052601160045260246000fd5b5060010190565b634e487b7160e01b600052604160045260246000fd5b601f82111561066b57600081815260208120601f850160051c810160208610156106485750805b601f850160051c820191505b8181101561066757828155600101610654565b5050505b505050565b67ffffffffffffffff8311156106885761068861060b565b61069c8361069683546105aa565b83610621565b6000601f8411600181146106d057600085156106b85750838201355b600019600387901b1c1916600186901b17835561072a565b600083815260209020601f19861690835b8281101561070157868501358255602094850194600190920191016106e1565b508682101561071e5760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b84868237600085820160008152848682379093019182525060200194935050505056fea2646970667358221220b55905797bd8395e3f1dcdaecb9b48ba2a1b4b80b337b53b97286550823b4a5b64736f6c634300080f0033"; + +type CustomModicumConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: CustomModicumConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class CustomModicum__factory extends ContractFactory { + constructor(...args: CustomModicumConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + CustomModicum & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): CustomModicum__factory { + return super.connect(runner) as CustomModicum__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): CustomModicumInterface { + return new Interface(_abi) as CustomModicumInterface; + } + static connect( + address: string, + runner?: ContractRunner | null + ): CustomModicum { + return new Contract(address, _abi, runner) as unknown as CustomModicum; + } +} diff --git a/src/generated/typechain-types/factories/TinyHops.sol/ModicumContract__factory.ts b/src/generated/typechain-types/factories/TinyHops.sol/ModicumContract__factory.ts new file mode 100644 index 0000000..d5581e8 --- /dev/null +++ b/src/generated/typechain-types/factories/TinyHops.sol/ModicumContract__factory.ts @@ -0,0 +1,49 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Interface, type ContractRunner } from "ethers"; +import type { + ModicumContract, + ModicumContractInterface, +} from "../../TinyHops.sol/ModicumContract"; + +const _abi = [ + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string", + }, + { + internalType: "string", + name: "params", + type: "string", + }, + ], + name: "runModuleWithDefaultMediators", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, +] as const; + +export class ModicumContract__factory { + static readonly abi = _abi; + static createInterface(): ModicumContractInterface { + return new Interface(_abi) as ModicumContractInterface; + } + static connect( + address: string, + runner?: ContractRunner | null + ): ModicumContract { + return new Contract(address, _abi, runner) as unknown as ModicumContract; + } +} diff --git a/src/generated/typechain-types/factories/TinyHops.sol/TinyHops__factory.ts b/src/generated/typechain-types/factories/TinyHops.sol/TinyHops__factory.ts new file mode 100644 index 0000000..59195a3 --- /dev/null +++ b/src/generated/typechain-types/factories/TinyHops.sol/TinyHops__factory.ts @@ -0,0 +1,491 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { + Signer, + AddressLike, + ContractDeployTransaction, + ContractRunner, +} from "ethers"; +import type { NonPayableOverrides } from "../../common"; +import type { TinyHops, TinyHopsInterface } from "../../TinyHops.sol/TinyHops"; + +const _abi = [ + { + inputs: [ + { + internalType: "address", + name: "_modicumContract", + type: "address", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "owner", + type: "address", + }, + ], + name: "WorkflowAdded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "jobId", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "balance", + type: "uint256", + }, + ], + name: "WorkflowStartedJob", + type: "event", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_workflowId", + type: "uint256", + }, + ], + name: "checkAllEntryStepsComplete", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "workflowID", + type: "uint256", + }, + { + internalType: "uint256", + name: "workflowIndex", + type: "uint256", + }, + ], + name: "checkPreviousLevelComplete", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "contractAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + ], + name: "getBalance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + { + internalType: "uint256", + name: "stepId", + type: "uint256", + }, + ], + name: "getStepStatus", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + ], + name: "getWorkFlowResults", + outputs: [ + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + { + internalType: "string[]", + name: "", + type: "string[]", + }, + { + internalType: "string[]", + name: "", + type: "string[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + ], + name: "getWorkFlowStatus", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_workflowId", + type: "uint256", + }, + { + internalType: "uint256", + name: "_stepId", + type: "uint256", + }, + ], + name: "getWorkHash", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "pure", + type: "function", + }, + { + inputs: [], + name: "job1", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "job2", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + ], + name: "ownerOf", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_jobID", + type: "uint256", + }, + { + internalType: "string", + name: "_cid", + type: "string", + }, + ], + name: "receiveJobResults", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "resultCIDs1", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "resultCIDs2", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "resultJobId1", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "resultJobId2", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "workflowId", + type: "uint256", + }, + ], + name: "startWorkflow", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + components: [ + { + internalType: "uint256", + name: "cost", + type: "uint256", + }, + { + internalType: "uint256", + name: "stepId", + type: "uint256", + }, + { + internalType: "string", + name: "cmd", + type: "string", + }, + { + internalType: "bytes", + name: "params", + type: "bytes", + }, + ], + internalType: "struct WorkflowEntry[][]", + name: "entries", + type: "tuple[][]", + }, + ], + internalType: "struct Workflow", + name: "workflow", + type: "tuple", + }, + ], + name: "storeWorkflow", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "workflowIdCounter", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, +] as const; + +const _bytecode = + "0x60806040523480156200001157600080fd5b50604051620025d1380380620025d18339810160408190526200003491620000bf565b6001600160a01b0381166200008f5760405162461bcd60e51b815260206004820152601f60248201527f436f6e74726163742063616e6e6f74206265207a65726f206164647265737300604482015260640160405180910390fd5b600080546001600160a01b039092166001600160a01b0319928316811790915560018054909216179055620000f1565b600060208284031215620000d257600080fd5b81516001600160a01b0381168114620000ea57600080fd5b9392505050565b6124d080620001016000396000f3fe6080604052600436106101445760003560e01c80636c0ff76b116100c0578063b061f8dc11610074578063e49e0bd111610059578063e49e0bd1146103b3578063f227a3e4146103d3578063f6b4dfb4146103e857600080fd5b8063b061f8dc1461036d578063be28b91d1461038357600080fd5b80637a494362116100a55780637a494362146102f1578063869507061461031357806399df8e431461032657600080fd5b80636c0ff76b146102c55780636cfac9e2146102db57600080fd5b8063288ed705116101175780634b14077b116100fc5780634b14077b146102325780635b8f66c1146102615780636352211e1461027757600080fd5b8063288ed705146101e55780633377368c1461020557600080fd5b806306ab218c146101495780631e01043914610174578063243d7a7b146101af57806325970baf146101c5575b600080fd5b34801561015557600080fd5b5061015e610408565b60405161016b9190611b77565b60405180910390f35b34801561018057600080fd5b506101a161018f366004611b8a565b60009081526005602052604090205490565b60405190815260200161016b565b3480156101bb57600080fd5b506101a1600f5481565b3480156101d157600080fd5b506101a16101e0366004611cd2565b610496565b3480156101f157600080fd5b506101a1610200366004611eef565b610674565b34801561021157600080fd5b506101a1610220366004611b8a565b60009081526003602052604090205490565b34801561023e57600080fd5b5061025261024d366004611b8a565b6106b2565b60405161016b93929190611f59565b34801561026d57600080fd5b506101a160155481565b34801561028357600080fd5b506102ad610292366004611b8a565b6000908152600260205260409020546001600160a01b031690565b6040516001600160a01b03909116815260200161016b565b3480156102d157600080fd5b506101a160105481565b3480156102e757600080fd5b506101a160115481565b3480156102fd57600080fd5b5061031161030c366004611fc5565b610ba8565b005b6101a1610321366004611b8a565b610cbd565b34801561033257600080fd5b506101a1610341366004611eef565b604080516020808201949094528082019290925280518083038201815260609092019052805191012090565b34801561037957600080fd5b506101a160145481565b34801561038f57600080fd5b506103a361039e366004611b8a565b610e62565b604051901515815260200161016b565b3480156103bf57600080fd5b506103a36103ce366004611eef565b610f31565b3480156103df57600080fd5b5061015e610ff8565b3480156103f457600080fd5b506000546102ad906001600160a01b031681565b6012805461041590612041565b80601f016020809104026020016040519081016040528092919081815260200182805461044190612041565b801561048e5780601f106104635761010080835404028352916020019161048e565b820191906000526020600020905b81548152906001019060200180831161047157829003601f168201915b505050505081565b6000806104a1611005565b60008181526004602052604081209192505b8451518110156105f8578154600190810180845560008481529184916104d9919061208b565b815481106104e9576104e96120a2565b90600052602060002001905060005b865180518490811061050c5761050c6120a2565b6020026020010151518110156105e357600087600001518481518110610534576105346120a2565b6020026020010151828151811061054d5761054d6120a2565b602090810291909101015183546001908101808655600086815292935085916105759161208b565b81548110610585576105856120a2565b906000526020600020906004020190508160200151816001018190555081604001518160020190816105b79190612107565b50606082015160038201906105cc9082612107565b5090519055806105db816121c7565b9150506104f8565b505080806105f0906121c7565b9150506104b3565b50600f5460009081526002602090815260409182902080547fffffffffffffffffffffffff000000000000000000000000000000000000000016339081179091558251858152918201527f37fa2470b7dca9b1757f47a69b611398adc772e255c4c8a322c05a6c0be5b91a910160405180910390a15092915050565b604080516020808201859052818301849052825180830384018152606090920183528151918101919091206000908152600c90915220545b92915050565b600081815260046020526040812060609182918291805b8254811015610711578260000181815481106106e7576106e76120a2565b6000918252602090912001546106fd90836121e0565b915080610709816121c7565b9150506106c9565b5060008167ffffffffffffffff81111561072d5761072d611ba3565b604051908082528060200260200182016040528015610756578160200160208202803683370190505b50905060008267ffffffffffffffff81111561077457610774611ba3565b6040519080825280602002602001820160405280156107a757816020015b60608152602001906001900390816107925790505b50905060008367ffffffffffffffff8111156107c5576107c5611ba3565b6040519080825280602002602001820160405280156107f857816020015b60608152602001906001900390816107e35790505b5090506000805b8654811015610b985760005b876000018281548110610820576108206120a2565b600091825260209091200154811015610b8557876000018281548110610848576108486120a2565b906000526020600020018181548110610863576108636120a2565b906000526020600020906004020160010154868481518110610887576108876120a2565b602002602001018181525050600d60006109098e8b60000186815481106108b0576108b06120a2565b9060005260206000200185815481106108cb576108cb6120a2565b906000526020600020906004020160010154604080516020808201949094528082019290925280518083038201815260609092019052805191012090565b8152602001908152602001600020805461092290612041565b80601f016020809104026020016040519081016040528092919081815260200182805461094e90612041565b801561099b5780601f106109705761010080835404028352916020019161099b565b820191906000526020600020905b81548152906001019060200180831161097e57829003601f168201915b50505050508584815181106109b2576109b26120a2565b6020026020010181905250610b478c8960000184815481106109d6576109d66120a2565b9060005260206000200183815481106109f1576109f16120a2565b90600052602060002090600402016040518060800160405290816000820154815260200160018201548152602001600282018054610a2e90612041565b80601f0160208091040260200160405190810160405280929190818152602001828054610a5a90612041565b8015610aa75780601f10610a7c57610100808354040283529160200191610aa7565b820191906000526020600020905b815481529060010190602001808311610a8a57829003601f168201915b50505050508152602001600382018054610ac090612041565b80601f0160208091040260200160405190810160405280929190818152602001828054610aec90612041565b8015610b395780601f10610b0e57610100808354040283529160200191610b39565b820191906000526020600020905b815481529060010190602001808311610b1c57829003601f168201915b505050505081525050611023565b848481518110610b5957610b596120a2565b60200260200101819052508280610b6f906121c7565b9350508080610b7d906121c7565b91505061080b565b5080610b90816121c7565b9150506107ff565b5092999198509650945050505050565b610be76040518060400160405280600581526020017f6a6f62496400000000000000000000000000000000000000000000000000000081525084611048565b610c5c6040518060400160405280600381526020017f636964000000000000000000000000000000000000000000000000000000000081525083838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506110aa92505050565b6000610c6b8484846003611108565b9050610c7681610e62565b15610c975760008181526003602081905260409091208190555b5050505050565b6000610ca2826111af565b9050610cae8282610f31565b15610c9057610c908282611276565b60008181526002602052604081205482906001600160a01b03163314610d505760405162461bcd60e51b815260206004820152602560248201527f4f6e6c7920746865206f776e65722063616e2063616c6c20746869732066756e60448201527f6374696f6e00000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b674563918244f40000341015610dce5760405162461bcd60e51b815260206004820152603b60248201527f5061796d656e74206f66206174206c656173742035204574686572207065722060448201527f73746570206973207265717569726564206d61796265206d6f726500000000006064820152608401610d47565b60008381526003602052604090205415610e2a5760405162461bcd60e51b815260206004820152601860248201527f576f726b666c6f7720616c7265616479207374617274656400000000000000006044820152606401610d47565b610e3483346117e0565b610e4683610e41856111af565b611276565b6000838152600360205260409020600190558291505b50919050565b6000818152600460205260408120815b8154811015610f275760005b826000018281548110610e9357610e936120a2565b600091825260209091200154811015610f14576000610edc86856000018581548110610ec157610ec16120a2565b9060005260206000200184815481106108cb576108cb6120a2565b6000818152600c6020526040902054909150600314610f015750600095945050505050565b5080610f0c816121c7565b915050610e7e565b5080610f1f816121c7565b915050610e72565b5060019392505050565b6000808215610f4857610f4560018461208b565b90505b600084815260046020526040902080548210610f69576000925050506106ac565b6000816000018381548110610f8057610f806120a2565b600091825260208220015491505b81811015610feb576000610fb188856000018781548110610ec157610ec16120a2565b6000818152600c6020526040902054909150600314610fd8576000955050505050506106ac565b5080610fe3816121c7565b915050610f8e565b5060019695505050505050565b6013805461041590612041565b600f805460009182611016836121c7565b9190505550600f54905090565b6060818101516000848152600b602052604090206110419190611810565b9392505050565b6110a6828260405160240161105e9291906121f8565b60408051601f198184030181529190526020810180516001600160e01b03167f9710a9d000000000000000000000000000000000000000000000000000000000179052611a23565b5050565b6110a682826040516024016110c092919061221a565b60408051601f198184030181529190526020810180516001600160e01b03167f4b5c427700000000000000000000000000000000000000000000000000000000179052611a23565b600084815260076020908152604080832054600a909252822054826111548383604080516020808201949094528082019290925280518083038201815260609092019052805191012090565b6000818152600c60209081526040808320899055600d909152902090915061117d878983612248565b506000838152600b6020908152604080832085845290915290206111a2878983612248565b5091979650505050505050565b60008181526004602052604081208054825b8181101561126e5782546001906000908590849081106111e3576111e36120a2565b600091825260208220015491505b8181101561124857600061121489886000018781548110610ec157610ec16120a2565b6000818152600c602052604081205491925003611235576000935050611248565b5080611240816121c7565b9150506111f1565b508161125957509095945050505050565b50508080611266906121c7565b9150506111c1565b509392505050565b6112b46040518060400160405280600981526020017f6e65787420737465700000000000000000000000000000000000000000000000815250611a44565b600082815260046020526040812080549091908290849081106112d9576112d96120a2565b600091825260208220015491505b81811015610c905761133a85846000018681548110611308576113086120a2565b906000526020600020018381548110611323576113236120a2565b906000526020600020906004020160000154611aa3565b6113786040518060400160405280600981526020017f7061737420636f73740000000000000000000000000000000000000000000000815250611a44565b6113b66040518060400160405280600e81526020017f6170706c79207661726961626c65000000000000000000000000000000000000815250611a44565b6114a061149b8460000186815481106113d1576113d16120a2565b9060005260206000200183815481106113ec576113ec6120a2565b9060005260206000209060040201600301805461140890612041565b80601f016020809104026020016040519081016040528092919081815260200182805461143490612041565b80156114815780601f1061145657610100808354040283529160200191611481565b820191906000526020600020905b81548152906001019060200180831161146457829003601f168201915b50505060008a8152600b6020526040902091506118109050565b611a44565b6114de6040518060400160405280601381526020017f70617374206170706c79207661726961626c6500000000000000000000000000815250611a44565b60015483546000916001600160a01b031690637ce7b17990869088908110611508576115086120a2565b906000526020600020018481548110611523576115236120a2565b90600052602060002090600402016000015486600001888154811061154a5761154a6120a2565b906000526020600020018581548110611565576115656120a2565b9060005260206000209060040201600201611658886000018a8154811061158e5761158e6120a2565b9060005260206000200187815481106115a9576115a96120a2565b906000526020600020906004020160030180546115c590612041565b80601f01602080910402602001604051908101604052809291908181526020018280546115f190612041565b801561163e5780601f106116135761010080835404028352916020019161163e565b820191906000526020600020905b81548152906001019060200180831161162157829003601f168201915b50505060008e8152600b6020526040902091506118109050565b6040518463ffffffff1660e01b8152600401611675929190612308565b60206040518083038185885af1158015611693573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906116b8919061239e565b600081815260076020526040902087905584549091508490869081106116e0576116e06120a2565b9060005260206000200182815481106116fb576116fb6120a2565b906000526020600020906004020160010154600a6000838152602001908152602001600020819055506001600c600061175e89886000018a81548110611743576117436120a2565b9060005260206000200187815481106108cb576108cb6120a2565b81526020808201929092526040908101600090812093909355838352600e8252808320889055600f54835260058252918290205482518981529182018490528183015290517fcf8e9c670e8c8b337fa6f8c784ff15304bcfabe402cdf9470265cc1b7b1ab9459181900360600190a1506117d98160016121e0565b90506112e7565b6000828152600560205260409020546117fa9082906121e0565b6000928352600560205260409092209190915550565b60408051602080820190925260008152835160609285810191829181880101905b81841015611a1757835160f01c8061184a6002876121e0565b9550816000036119b557855160c01c6118646008886121e0565b965060008167ffffffffffffffff1667ffffffffffffffff81111561188b5761188b611ba3565b6040519080825280601f01601f1916602001820160405280156118b5576020820181803683370190505b50905060006118c4888a61208b565b905060005b8367ffffffffffffffff168167ffffffffffffffff161015611972578d6118fa67ffffffffffffffff8316846121e0565b8151811061190a5761190a6120a2565b602001015160f81c60f81b838267ffffffffffffffff1681518110611931576119316120a2565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508061196a816123b7565b9150506118c9565b5061198767ffffffffffffffff84168a6121e0565b9850898260405160200161199c9291906123de565b6040516020818303038152906040529950505050611a10565b81600103611a1057855160c01c6119cd6008886121e0565b9650878a60008367ffffffffffffffff1681526020019081526020016000206040516020016119fd92919061240d565b6040516020818303038152906040529750505b5050611831565b50929695505050505050565b80516a636f6e736f6c652e6c6f67602083016000808483855afa5050505050565b611aa081604051602401611a589190611b77565b60408051601f198184030181529190526020810180516001600160e01b03167f41304fac00000000000000000000000000000000000000000000000000000000179052611a23565b50565b600082815260056020526040902054811115611b015760405162461bcd60e51b815260206004820152601760248201527f6e6f7420656e6f7567682066756e647320746f2072756e0000000000000000006044820152606401610d47565b6000828152600560205260409020546117fa90829061208b565b60005b83811015611b36578181015183820152602001611b1e565b83811115611b45576000848401525b50505050565b60008151808452611b63816020860160208601611b1b565b601f01601f19169290920160200192915050565b6020815260006110416020830184611b4b565b600060208284031215611b9c57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b6040516020810167ffffffffffffffff81118282101715611bdc57611bdc611ba3565b60405290565b6040516080810167ffffffffffffffff81118282101715611bdc57611bdc611ba3565b604051601f8201601f1916810167ffffffffffffffff81118282101715611c2e57611c2e611ba3565b604052919050565b600067ffffffffffffffff821115611c5057611c50611ba3565b5060051b60200190565b600067ffffffffffffffff831115611c7457611c74611ba3565b611c87601f8401601f1916602001611c05565b9050828152838383011115611c9b57600080fd5b828260208301376000602084830101529392505050565b600082601f830112611cc357600080fd5b61104183833560208501611c5a565b600060208284031215611ce457600080fd5b67ffffffffffffffff82351115611cfa57600080fd5b60208235830184031215611d0d57600080fd5b611d15611bb9565b67ffffffffffffffff83358401351115611d2e57600080fd5b82358301803501601f81018513611d4457600080fd5b611d56611d518235611c36565b611c05565b81358082526020808301929160051b840101871015611d7457600080fd5b602083015b6020843560051b850101811015611ee25767ffffffffffffffff81351115611da057600080fd5b8035840188603f820112611db357600080fd5b611dc3611d516020830135611c36565b602082810135808352908201919060051b83016040018b1015611de557600080fd5b604083015b6040602085013560051b850101811015611ed15767ffffffffffffffff81351115611e1457600080fd5b803584016080818e03603f19011215611e2c57600080fd5b611e34611be2565b604082013581526060820135602082015267ffffffffffffffff60808301351115611e5e57600080fd5b8d605f608084013584010112611e7357600080fd5b611e8c8e60808401358401604081013590606001611c5a565b604082015267ffffffffffffffff60a08301351115611eaa57600080fd5b611ebd8e604060a0850135850101611cb2565b606082015284525060209283019201611dea565b508552505060209283019201611d79565b5083525090949350505050565b60008060408385031215611f0257600080fd5b50508035926020909101359150565b600081518084526020808501808196508360051b8101915082860160005b858110156111a2578284038952611f47848351611b4b565b98850198935090840190600101611f2f565b606080825284519082018190526000906020906080840190828801845b82811015611f9257815184529284019290840190600101611f76565b50505083810382850152611fa68187611f11565b9150508281036040840152611fbb8185611f11565b9695505050505050565b600080600060408486031215611fda57600080fd5b83359250602084013567ffffffffffffffff80821115611ff957600080fd5b818601915086601f83011261200d57600080fd5b81358181111561201c57600080fd5b87602082850101111561202e57600080fd5b6020830194508093505050509250925092565b600181811c9082168061205557607f821691505b602082108103610e5c57634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008282101561209d5761209d612075565b500390565b634e487b7160e01b600052603260045260246000fd5b601f82111561210257600081815260208120601f850160051c810160208610156120df5750805b601f850160051c820191505b818110156120fe578281556001016120eb565b5050505b505050565b815167ffffffffffffffff81111561212157612121611ba3565b6121358161212f8454612041565b846120b8565b602080601f83116001811461216a57600084156121525750858301515b600019600386901b1c1916600185901b1785556120fe565b600085815260208120601f198616915b828110156121995788860151825594840194600190910190840161217a565b50858210156121b75787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6000600182016121d9576121d9612075565b5060010190565b600082198211156121f3576121f3612075565b500190565b60408152600061220b6040830185611b4b565b90508260208301529392505050565b60408152600061222d6040830185611b4b565b828103602084015261223f8185611b4b565b95945050505050565b67ffffffffffffffff83111561226057612260611ba3565b6122748361226e8354612041565b836120b8565b6000601f8411600181146122a857600085156122905750838201355b600019600387901b1c1916600186901b178355610c90565b600083815260209020601f19861690835b828110156122d957868501358255602094850194600190920191016122b9565b50868210156122f65760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b60408152600080845461231a81612041565b806040860152606060018084166000811461233c576001811461235657612387565b60ff1985168884015283151560051b880183019550612387565b8960005260208060002060005b8681101561237e5781548b8201870152908401908201612363565b8a018501975050505b5050505050828103602084015261223f8185611b4b565b6000602082840312156123b057600080fd5b5051919050565b600067ffffffffffffffff8083168181036123d4576123d4612075565b6001019392505050565b600083516123f0818460208801611b1b565b835190830190612404818360208801611b1b565b01949350505050565b6000835160206124208285838901611b1b565b81840191506000855461243281612041565b6001828116801561244a576001811461245f5761248b565b60ff198416875282151583028701945061248b565b896000528560002060005b848110156124835781548982015290830190870161246a565b505082870194505b5092999850505050505050505056fea264697066735822122003de811793ce778b5a91a5676cfb55a5b3a04b855da64ce98c5562cafdd9ef9264736f6c634300080f0033"; + +type TinyHopsConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: TinyHopsConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class TinyHops__factory extends ContractFactory { + constructor(...args: TinyHopsConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + _modicumContract: AddressLike, + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(_modicumContract, overrides || {}); + } + override deploy( + _modicumContract: AddressLike, + overrides?: NonPayableOverrides & { from?: string } + ) { + return super.deploy(_modicumContract, overrides || {}) as Promise< + TinyHops & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect(runner: ContractRunner | null): TinyHops__factory { + return super.connect(runner) as TinyHops__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): TinyHopsInterface { + return new Interface(_abi) as TinyHopsInterface; + } + static connect(address: string, runner?: ContractRunner | null): TinyHops { + return new Contract(address, _abi, runner) as unknown as TinyHops; + } +} diff --git a/src/generated/typechain-types/factories/TinyHops.sol/index.ts b/src/generated/typechain-types/factories/TinyHops.sol/index.ts new file mode 100644 index 0000000..66d0746 --- /dev/null +++ b/src/generated/typechain-types/factories/TinyHops.sol/index.ts @@ -0,0 +1,5 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { ModicumContract__factory } from "./ModicumContract__factory"; +export { TinyHops__factory } from "./TinyHops__factory"; diff --git a/src/generated/typechain-types/factories/index.ts b/src/generated/typechain-types/factories/index.ts index 66d0746..c1c6454 100644 --- a/src/generated/typechain-types/factories/index.ts +++ b/src/generated/typechain-types/factories/index.ts @@ -1,5 +1,5 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ -export { ModicumContract__factory } from "./ModicumContract__factory"; -export { TinyHops__factory } from "./TinyHops__factory"; +export * as tinyHopsSol from "./TinyHops.sol"; +export { CustomModicum__factory } from "./CustomModicum__factory"; diff --git a/src/generated/typechain-types/factories/library/LibTinyHopsTemplateResolver__factory.ts b/src/generated/typechain-types/factories/library/LibTinyHopsTemplateResolver__factory.ts new file mode 100644 index 0000000..84c6a21 --- /dev/null +++ b/src/generated/typechain-types/factories/library/LibTinyHopsTemplateResolver__factory.ts @@ -0,0 +1,86 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + Contract, + ContractFactory, + ContractTransactionResponse, + Interface, +} from "ethers"; +import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers"; +import type { NonPayableOverrides } from "../../common"; +import type { + LibTinyHopsTemplateResolver, + LibTinyHopsTemplateResolverInterface, +} from "../../library/LibTinyHopsTemplateResolver"; + +const _abi = [ + { + inputs: [ + { + internalType: "bytes", + name: "byteStream", + type: "bytes", + }, + ], + name: "validateByteStream", + outputs: [], + stateMutability: "pure", + type: "function", + }, +] as const; + +const _bytecode = + "0x61080161003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063ac5f9e7114610045578063fa55b4381461006e575b600080fd5b610058610053366004610585565b610083565b60405161006591906105f6565b60405180910390f35b61008161007c366004610629565b610296565b005b60408051602080820190925260008152835160609285810191829181880101905b8184101561028a57835160f01c806100bd60028761067c565b95508160000361022857855160c01c6100d760088861067c565b965060008167ffffffffffffffff1667ffffffffffffffff8111156100fe576100fe6104e2565b6040519080825280601f01601f191660200182016040528015610128576020820181803683370190505b5090506000610137888a610694565b905060005b8367ffffffffffffffff168167ffffffffffffffff1610156101e5578d61016d67ffffffffffffffff83168461067c565b8151811061017d5761017d6106ab565b602001015160f81c60f81b838267ffffffffffffffff16815181106101a4576101a46106ab565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806101dd816106c1565b91505061013c565b506101fa67ffffffffffffffff84168a61067c565b9850898260405160200161020f9291906106e8565b6040516020818303038152906040529950505050610283565b8160010361028357855160c01c61024060088861067c565b9650878a60008367ffffffffffffffff168152602001908152602001600020604051602001610270929190610717565b6040516020818303038152906040529750505b50506100a4565b50929695505050505050565b8051602080830191808401909101905b818310156104dc57816102ba84600261067c565b111561030d5760405162461bcd60e51b815260206004820152601160248201527f496e636f6d706c6574652070726566697800000000000000000000000000000060448201526064015b60405180910390fd5b825160f01c61031d60028561067c565b93508061ffff16600003610416578261033785600861067c565b11156103855760405162461bcd60e51b815260206004820152601660248201527f496e636f6d706c6574652074657874206c656e677468000000000000000000006044820152606401610304565b835160c01c61039560088661067c565b9450836103ac67ffffffffffffffff83168761067c565b11156103fa5760405162461bcd60e51b815260206004820152601460248201527f496e636f6d706c657465207465787420646174610000000000000000000000006044820152606401610304565b61040e67ffffffffffffffff82168661067c565b9450506104d6565b8061ffff1660010361048e578261042e85600861067c565b111561047c5760405162461bcd60e51b815260206004820152601160248201527f496e636f6d706c657465207374657049640000000000000000000000000000006044820152606401610304565b61048760088561067c565b93506104d6565b60405162461bcd60e51b815260206004820152601460248201527f496e76616c6964207365676d656e7420747970650000000000000000000000006044820152606401610304565b506102a6565b50505050565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261050957600080fd5b813567ffffffffffffffff80821115610524576105246104e2565b604051601f8301601f19908116603f0116810190828211818310171561054c5761054c6104e2565b8160405283815286602085880101111561056557600080fd5b836020870160208301376000602085830101528094505050505092915050565b6000806040838503121561059857600080fd5b823567ffffffffffffffff8111156105af57600080fd5b6105bb858286016104f8565b95602094909401359450505050565b60005b838110156105e55781810151838201526020016105cd565b838111156104dc5750506000910152565b60208152600082518060208401526106158160408501602087016105ca565b601f01601f19169190910160400192915050565b60006020828403121561063b57600080fd5b813567ffffffffffffffff81111561065257600080fd5b61065e848285016104f8565b949350505050565b634e487b7160e01b600052601160045260246000fd5b6000821982111561068f5761068f610666565b500190565b6000828210156106a6576106a6610666565b500390565b634e487b7160e01b600052603260045260246000fd5b600067ffffffffffffffff8083168181036106de576106de610666565b6001019392505050565b600083516106fa8184602088016105ca565b83519083019061070e8183602088016105ca565b01949350505050565b60008351602061072a82858389016105ca565b845491840191600090600181811c908083168061074857607f831692505b858310810361076557634e487b7160e01b85526022600452602485fd5b808015610779576001811461078e576107bb565b60ff19851688528315158402880195506107bb565b60008b81526020902060005b858110156107b35781548a82015290840190880161079a565b505083880195505b50939a995050505050505050505056fea26469706673582212203674766606882e1f46bc60fda5e131ebb39d4b5ead98a1262efbcb04d508601764736f6c634300080f0033"; + +type LibTinyHopsTemplateResolverConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: LibTinyHopsTemplateResolverConstructorParams +): xs is ConstructorParameters => xs.length > 1; + +export class LibTinyHopsTemplateResolver__factory extends ContractFactory { + constructor(...args: LibTinyHopsTemplateResolverConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override getDeployTransaction( + overrides?: NonPayableOverrides & { from?: string } + ): Promise { + return super.getDeployTransaction(overrides || {}); + } + override deploy(overrides?: NonPayableOverrides & { from?: string }) { + return super.deploy(overrides || {}) as Promise< + LibTinyHopsTemplateResolver & { + deploymentTransaction(): ContractTransactionResponse; + } + >; + } + override connect( + runner: ContractRunner | null + ): LibTinyHopsTemplateResolver__factory { + return super.connect(runner) as LibTinyHopsTemplateResolver__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): LibTinyHopsTemplateResolverInterface { + return new Interface(_abi) as LibTinyHopsTemplateResolverInterface; + } + static connect( + address: string, + runner?: ContractRunner | null + ): LibTinyHopsTemplateResolver { + return new Contract( + address, + _abi, + runner + ) as unknown as LibTinyHopsTemplateResolver; + } +} diff --git a/src/generated/typechain-types/factories/library/index.ts b/src/generated/typechain-types/factories/library/index.ts new file mode 100644 index 0000000..3aca09f --- /dev/null +++ b/src/generated/typechain-types/factories/library/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { LibTinyHopsTemplateResolver__factory } from "./LibTinyHopsTemplateResolver__factory"; diff --git a/src/generated/typechain-types/hardhat.d.ts b/src/generated/typechain-types/hardhat.d.ts index ea4a7d0..9c89877 100644 --- a/src/generated/typechain-types/hardhat.d.ts +++ b/src/generated/typechain-types/hardhat.d.ts @@ -13,6 +13,10 @@ import * as Contracts from "."; declare module "hardhat/types/runtime" { interface HardhatEthersHelpers extends HardhatEthersHelpersBase { + getContractFactory( + name: "CustomModicum", + signerOrOptions?: ethers.Signer | FactoryOptions + ): Promise; getContractFactory( name: "ModicumContract", signerOrOptions?: ethers.Signer | FactoryOptions @@ -22,6 +26,11 @@ declare module "hardhat/types/runtime" { signerOrOptions?: ethers.Signer | FactoryOptions ): Promise; + getContractAt( + name: "CustomModicum", + address: string | ethers.Addressable, + signer?: ethers.Signer + ): Promise; getContractAt( name: "ModicumContract", address: string | ethers.Addressable, @@ -33,6 +42,10 @@ declare module "hardhat/types/runtime" { signer?: ethers.Signer ): Promise; + deployContract( + name: "CustomModicum", + signerOrOptions?: ethers.Signer | DeployContractOptions + ): Promise; deployContract( name: "ModicumContract", signerOrOptions?: ethers.Signer | DeployContractOptions @@ -42,6 +55,11 @@ declare module "hardhat/types/runtime" { signerOrOptions?: ethers.Signer | DeployContractOptions ): Promise; + deployContract( + name: "CustomModicum", + args: any[], + signerOrOptions?: ethers.Signer | DeployContractOptions + ): Promise; deployContract( name: "ModicumContract", args: any[], diff --git a/src/generated/typechain-types/index.ts b/src/generated/typechain-types/index.ts index 748d91b..40c8af9 100644 --- a/src/generated/typechain-types/index.ts +++ b/src/generated/typechain-types/index.ts @@ -1,8 +1,12 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ -export type { ModicumContract } from "./ModicumContract"; -export type { TinyHops } from "./TinyHops"; +import type * as tinyHopsSol from "./TinyHops.sol"; +export type { tinyHopsSol }; +export type { CustomModicum } from "./CustomModicum"; export * as factories from "./factories"; -export { ModicumContract__factory } from "./factories/ModicumContract__factory"; -export { TinyHops__factory } from "./factories/TinyHops__factory"; +export { CustomModicum__factory } from "./factories/CustomModicum__factory"; +export type { ModicumContract } from "./TinyHops.sol/ModicumContract"; +export { ModicumContract__factory } from "./factories/TinyHops.sol/ModicumContract__factory"; +export type { TinyHops } from "./TinyHops.sol/TinyHops"; +export { TinyHops__factory } from "./factories/TinyHops.sol/TinyHops__factory"; diff --git a/src/generated/typechain-types/library/LibTinyHopsTemplateResolver.ts b/src/generated/typechain-types/library/LibTinyHopsTemplateResolver.ts new file mode 100644 index 0000000..011d899 --- /dev/null +++ b/src/generated/typechain-types/library/LibTinyHopsTemplateResolver.ts @@ -0,0 +1,94 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BytesLike, + FunctionFragment, + Result, + Interface, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedListener, + TypedContractMethod, +} from "../common"; + +export interface LibTinyHopsTemplateResolverInterface extends Interface { + getFunction(nameOrSignature: "validateByteStream"): FunctionFragment; + + encodeFunctionData( + functionFragment: "validateByteStream", + values: [BytesLike] + ): string; + + decodeFunctionResult( + functionFragment: "validateByteStream", + data: BytesLike + ): Result; +} + +export interface LibTinyHopsTemplateResolver extends BaseContract { + connect(runner?: ContractRunner | null): LibTinyHopsTemplateResolver; + waitForDeployment(): Promise; + + interface: LibTinyHopsTemplateResolverInterface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + validateByteStream: TypedContractMethod< + [byteStream: BytesLike], + [void], + "view" + >; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "validateByteStream" + ): TypedContractMethod<[byteStream: BytesLike], [void], "view">; + + filters: {}; +} diff --git a/src/generated/typechain-types/library/index.ts b/src/generated/typechain-types/library/index.ts new file mode 100644 index 0000000..757da4b --- /dev/null +++ b/src/generated/typechain-types/library/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { LibTinyHopsTemplateResolver } from "./LibTinyHopsTemplateResolver"; diff --git a/src/generated/workflow_schema.ts b/src/generated/workflow_schema.ts new file mode 100644 index 0000000..2783eef --- /dev/null +++ b/src/generated/workflow_schema.ts @@ -0,0 +1,21 @@ +export type Version = string; +type AlwaysFalse = any; +export type StepName = string; +export type StepId = string; +export type StepDesc = string; +export type StepModule = any; +export interface StepItem { + stepName?: StepName; + stepId: StepId; + stepDesc?: StepDesc; + stepModule: StepModule; + [k: string]: any; +} +export type StepItems = StepItem[]; +export type OneOfStepItemStepItemsNHbN9TxM = StepItems | StepItem; +export type Steps = OneOfStepItemStepItemsNHbN9TxM[]; +export interface Workflow { + version: Version; + steps: Steps; + [k: string]: any; +} \ No newline at end of file diff --git a/src/lib/index.ts b/src/lib/index.ts new file mode 100644 index 0000000..b18fc1a --- /dev/null +++ b/src/lib/index.ts @@ -0,0 +1,119 @@ +import fs from "fs"; +import ajv from "ajv"; +import path from "path"; +import thopsSchema from "../../schema.json"; +import { + WorkflowEntryStruct, + WorkflowStruct, +} from "../generated/typechain-types/TinyHops.sol/TinyHops"; +import { StepItem, Workflow } from "../generated/workflow_schema"; +import { ethers, parseEther } from "ethers"; + +interface StepModule { + stepId: number; + cost: string; + cmd: string; + params: string; +} + +const convertEntryToWorkflowEntry = (entry: StepItem): WorkflowEntryStruct => { + const stepId = entry.stepId; + const stepModule = entry.stepModule as StepModule; + const cost = parseEther(stepModule.cost); + const cmd = stepModule.cmd; + const params = stringToByteStream(stepModule.params); + console.log("string",stepModule.params) + console.log("bytes",params) + console.log("hex", Buffer.from(params).toString("hex")) + return { + stepId, + cost, + cmd, + params, + }; +}; +// Helper function to convert a number to a Uint8Array of specified bytes +/*function numberToUint8Array(num: number, bytes: number): Uint8Array { + const arr = new Uint8Array(bytes); + for (let i = 0; i < bytes; i++) { + arr[i] = (num >>> ((bytes - i - 1) * 8)) & 0xff; + } + return arr; +}*/ + + + +function numberToUint8Array(num: number, bytes: number): Uint8Array { + const arr = new Uint8Array(bytes); + const bigNum = BigInt(num); + for (let i = 0; i < bytes; i++) { + const shiftAmount = BigInt(bytes - i - 1) * BigInt(8); + const byteValue = Number((bigNum >> shiftAmount) & BigInt(0xff)); + arr[i] = byteValue; + } + return arr; +} + +export const stringToByteStream = (params: string): Uint8Array => { + const segments: Uint8Array[] = []; + let match: RegExpExecArray | null; + const regex = /{{stepId\s*:\s*(\d+)}}|([^{}]+)/g; + + while ((match = regex.exec(params)) !== null) { + if (match[1] !== undefined) { + // stepId segment + const segmentType = numberToUint8Array(1, 2); + const stepId = numberToUint8Array(Number(match[1]),8); + segments.push(new Uint8Array([...segmentType, ...stepId])); + } else if (match[2] !== undefined) { + // Text segment + const segmentType = numberToUint8Array(0, 2); + const text = new TextEncoder().encode(match[2]); + console.log("text", text) + const textLength = numberToUint8Array(text.length, 8); + console.log("textLength", textLength, text.length) + segments.push(new Uint8Array([...segmentType, ...textLength, ...text])); + } + } + + const totalLength = segments.reduce( + (acc, segment) => acc + segment.length, + 0 + ); + const byteStream = new Uint8Array(totalLength); + let offset = 0; + + for (const segment of segments) { + byteStream.set(segment, offset); + offset += segment.length; + } + + return byteStream; +}; + +export const convertThopsToWorkflow = (configPath: string): WorkflowStruct => { + const data = JSON.parse(fs.readFileSync(path.resolve(configPath), "utf-8")); + const validator = new ajv({ strict: false }); + const validate = validator.compile(thopsSchema); + const result = validate(data); + if (result === false) { + throw new Error("Schema Invalid" + validator.errorsText(validate.errors)); + } + const workflow = data as Workflow; + const workflowEntries: WorkflowEntryStruct[][] = workflow.steps.map( + (stepGroup) => { + // check if stepGroup is an array + + if (Array.isArray(stepGroup)) { + return stepGroup.map((step: StepItem) => { + return convertEntryToWorkflowEntry(step); + }); + } else { + return [convertEntryToWorkflowEntry(stepGroup)]; + } + } + ); + return { + entries: workflowEntries, + }; +}; diff --git a/test/foundry/TinyHops.t.sol b/test/foundry/TinyHops.t.sol index 811b982..f088802 100644 --- a/test/foundry/TinyHops.t.sol +++ b/test/foundry/TinyHops.t.sol @@ -37,6 +37,14 @@ contract TinyHopsTest is Test { ); } + function testStreamHex() public view { + bytes memory hello = buildWorkflowParamText("hello world "); + bytes memory stepId1 = buildWorkflowParamVar(1); + + bytes memory testStream = abi.encodePacked(hello, stepId1); + console.logBytes(testStream); + } + function getTestStream() public view returns (bytes memory testStream) { bytes memory hello = buildWorkflowParamText("hello "); bytes memory world = buildWorkflowParamText(" world "); diff --git a/tsconfig.json b/tsconfig.json index 2d12e0c..2545b0a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "experimentalDecorators": true, - "target": "es5", + "target": "ES2020", "module": "commonjs", "lib": [ "es6",