create-dubhe 1.2.0-pre.122 → 1.2.0-pre.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +16 -1
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +6 -2
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.lock +2 -2
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +16 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +0 -16
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +51 -35
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +31 -135
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +5 -5
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +1 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +128 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +33 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +151 -157
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +6 -6
- package/templates/contract/sui-template/src/dubhe/Move.lock +2 -2
- package/templates/contract/sui-template/src/dubhe/sources/codegen/dapp_key.move +16 -1
- package/templates/contract/sui-template/src/dubhe/sources/codegen/error.move +0 -16
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_service.move +51 -35
- package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +31 -135
- package/templates/contract/sui-template/src/dubhe/sources/tests/fee_test.move +5 -5
- package/templates/contract/sui-template/src/dubhe/sources/tests/integration_test.move +1 -1
- package/templates/contract/sui-template/src/dubhe/sources/tests/listing_test.move +128 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_object_test.move +33 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_scene_test.move +151 -157
- package/templates/contract/sui-template/src/dubhe/sources/tests/user_storage_test.move +6 -6
- package/templates/contract/sui-template/src/template/sources/codegen/dapp_key.move +16 -1
- package/templates/contract/sui-template/src/template/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-farm/docker-compose.yml +2 -5
- package/templates/nextjs/sui-farm/packages/client/src/app/admin/page.tsx +618 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ProxyCard.tsx +1 -4
- package/templates/nextjs/sui-farm/packages/client/src/app/hooks/useSessionKey.ts +2 -4
- package/templates/nextjs/sui-farm/packages/client/src/app/page.tsx +125 -17
- package/templates/nextjs/sui-farm/packages/client/src/app/providers.tsx +4 -7
- package/templates/nextjs/sui-farm/packages/contracts/Dockerfile +1 -1
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/dapp_key.move +16 -1
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_damage.move +10 -12
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/crow_system.move +1 -5
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +16 -1
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.lock +2 -2
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +16 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +0 -16
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +51 -35
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +31 -135
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +5 -5
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +1 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +128 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +33 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +151 -157
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +6 -6
package/dist/cli.js
CHANGED
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bin/cli.ts","../src/config/chains.ts","../package.json","../src/exists.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport glob from 'fast-glob';\nimport yargsInteractive from 'yargs-interactive';\nimport { CHAINS } from '../config/chains';\nimport packageJson from '../../package.json';\nimport { exists } from '../exists';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nconst cwd = process.cwd();\n\nconst init = async () => {\n // Prepare chain options\n const chainChoices = CHAINS.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 1: Choose project name and chain\n const firstStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n projectName: {\n describe: 'Name your project',\n type: 'input'\n },\n chain: {\n describe: 'Pick your chain',\n type: 'list',\n choices: chainChoices.map((c) => c.value)\n },\n dubheVersion: {\n describe: 'The version of Dubhe packages to use, defaults to latest',\n type: 'input',\n default: packageJson.version\n }\n });\n\n const { projectName, chain, dubheVersion } = firstStep;\n if (!projectName) throw new Error('No project name provided.');\n\n // Get available templates based on the selected chain\n const selectedChain = CHAINS.find((c) => c.value === chain);\n if (!selectedChain) {\n throw new Error('Invalid chain selection');\n }\n\n // Prepare platform options\n const platformChoices = selectedChain.supportedTemplates.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 2: Choose platform\n const secondStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n platform: {\n describe: 'Pick your platform',\n type: 'list',\n choices: platformChoices.map((c) => c.value)\n }\n });\n\n const { platform } = secondStep;\n\n const selectedTemplate = selectedChain.supportedTemplates.find((t) => t.value === platform);\n if (!selectedTemplate) {\n throw new Error('Invalid platform selection');\n }\n\n const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);\n const pkgManager = pkgInfo ? pkgInfo.name : 'npm';\n\n const sourceDir = path.join(\n __dirname,\n '..',\n 'templates',\n selectedTemplate.path.replace('{chain}', chain)\n );\n\n if (!(await exists(sourceDir))) {\n throw new Error(`Template directory not found: ${sourceDir}`);\n }\n\n const destDir = path.join(process.cwd(), projectName);\n if (await exists(destDir)) {\n throw new Error(`Target directory \"${destDir}\" already exists.`);\n }\n\n const files = await glob('**/*', { cwd: sourceDir, dot: true });\n\n for (const filename of files) {\n const sourceFile = path.join(sourceDir, filename);\n const destFile = path.join(destDir, filename);\n\n await fs.mkdir(path.dirname(destFile), { recursive: true });\n\n if (/package\\.json$/.test(sourceFile)) {\n const source = await fs.readFile(sourceFile, 'utf-8');\n await fs.writeFile(destFile, source.replaceAll(/{{dubhe-version}}/g, dubheVersion), 'utf-8');\n } else if (/\\.gitignore_$/.test(sourceFile)) {\n await fs.copyFile(sourceFile, destFile.replace(/_$/, ''));\n } else {\n await fs.copyFile(sourceFile, destFile);\n }\n }\n\n const cdProjectName = path.relative(cwd, destDir);\n\n const styles = {\n success: '\\x1b[32m%s\\x1b[0m',\n info: '\\x1b[36m%s\\x1b[0m',\n command: '\\x1b[33m%s\\x1b[0m',\n separator: '\\x1b[90m%s\\x1b[0m'\n };\n\n console.log('\\n' + '='.repeat(60));\n console.log(styles.success, '🎉 Project creation successful!');\n console.log(styles.info, `📁 Project location: ${destDir}`);\n console.log(styles.separator, '-'.repeat(60));\n console.log(styles.info, 'Next steps:\\n');\n\n if (destDir !== cwd) {\n console.log(\n styles.command,\n ` cd ${cdProjectName.includes(' ') ? `\"${cdProjectName}\"` : cdProjectName}`\n );\n }\n\n const actualTemplate = selectedTemplate.value;\n\n switch (actualTemplate) {\n case '101':\n case 'web':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n console.log(styles.command, ` ${pkgManager} run dev`);\n break;\n case 'contract':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n break;\n }\n\n console.log(styles.separator, '\\n' + '='.repeat(60) + '\\n');\n};\n\nfunction pkgFromUserAgent(userAgent: string | undefined) {\n if (!userAgent) return undefined;\n const pkgSpec = userAgent.split(' ')[0];\n const pkgSpecArr = pkgSpec.split('/');\n return {\n name: pkgSpecArr[0],\n version: pkgSpecArr[1]\n };\n}\n\ninit().catch((e) => {\n console.error(e);\n});\n","interface Template {\n title: string;\n description: string;\n value: string;\n path: string;\n}\n\ninterface Chain {\n title: string;\n description: string;\n value: string;\n supportedTemplates: Template[];\n}\n\nconst TEMPLATES = {\n QUICK_START: {\n title: '101',\n description: 'Quick start',\n value: '101',\n path: '101/{chain}-template'\n },\n WEB: {\n title: 'Web',\n description: 'Web template',\n value: 'web',\n path: 'nextjs/{chain}-template'\n },\n CONTRACT: {\n title: 'Contract',\n description: 'Contract template',\n value: 'contract',\n path: 'contract/{chain}-template'\n }\n} as const;\n\nexport const CHAINS: Chain[] = [\n {\n title: 'sui',\n description: 'Sui',\n value: 'sui',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'aptos',\n description: 'Aptos',\n value: 'aptos',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'rooch',\n description: 'Rooch',\n value: 'rooch',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'initia',\n description: 'Initia',\n value: 'initia',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'movement',\n description: 'Movement',\n value: 'movement',\n supportedTemplates: [TEMPLATES.QUICK_START]\n }\n];\n","{\n \"name\": \"create-dubhe\",\n \"version\": \"1.2.0-pre.122\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\n },\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"type\": \"module\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run type-check && pnpm run build:js\",\n \"build:js\": \"tsup && pnpm run copy-templates\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"cocos-js-build\": \"cd cocos-lib-builder && npm i && browserify aptos.js -p esmify > ../templates/cocos/aptos-template/assets/lib/dubhe.js && browserify sui.js -p esmify > ../templates/cocos/sui-template/assets/lib/dubhe.js\",\n \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"lint\": \"eslint . --ext .ts\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm lint && pnpm type-check\"\n },\n \"dependencies\": {\n \"browser-resolve\": \"^2.0.0\",\n \"browser-sync\": \"^2.29.3\",\n \"fast-glob\": \"^3.3.3\",\n \"yargs-interactive\": \"^3.0.1\"\n },\n \"devDependencies\": {\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"@types/yargs-interactive\": \"^2.1.6\",\n \"browserify\": \"^17.0.0\",\n \"cross-spawn\": \"^7.0.3\",\n \"eslint\": \"^9.0.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"esmify\": \"^2.1.1\",\n \"kolorist\": \"^1.7.0\",\n \"prettier\": \"3.3.3\",\n \"prompts\": \"^2.4.2\",\n \"typescript\": \"^5.8.3\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","import fs from 'node:fs/promises';\n\nexport async function exists(path: string) {\n try {\n await fs.access(path);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,OAAOA,SAAQ;AACf,OAAO,UAAU;AACjB,OAAO,UAAU;AACjB,OAAO,sBAAsB;;;ACU7B,IAAM,YAAY;AAAA,EAChB,aAAa;AAAA,IACX,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA,KAAK;AAAA,IACH,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA,UAAU;AAAA,IACR,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AACF;AAEO,IAAM,SAAkB;AAAA,EAC7B;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,aAAa,UAAU,KAAK,UAAU,QAAQ;AAAA,EAC/E;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,aAAa,UAAU,KAAK,UAAU,QAAQ;AAAA,EAC/E;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,WAAW;AAAA,EAC5C;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,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AAAA,IAClB,SAAS,WAAW,CAAC;AAAA,EACvB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACjB,CAAC;","names":["fs","path","fs"]}
|
|
1
|
+
{"version":3,"sources":["../src/bin/cli.ts","../src/config/chains.ts","../package.json","../src/exists.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport glob from 'fast-glob';\nimport yargsInteractive from 'yargs-interactive';\nimport { CHAINS } from '../config/chains';\nimport packageJson from '../../package.json';\nimport { exists } from '../exists';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nconst cwd = process.cwd();\n\nconst init = async () => {\n // Prepare chain options\n const chainChoices = CHAINS.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 1: Choose project name and chain\n const firstStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n projectName: {\n describe: 'Name your project',\n type: 'input'\n },\n chain: {\n describe: 'Pick your chain',\n type: 'list',\n choices: chainChoices.map((c) => c.value)\n },\n dubheVersion: {\n describe: 'The version of Dubhe packages to use, defaults to latest',\n type: 'input',\n default: packageJson.version\n }\n });\n\n const { projectName, chain, dubheVersion } = firstStep;\n if (!projectName) throw new Error('No project name provided.');\n\n // Get available templates based on the selected chain\n const selectedChain = CHAINS.find((c) => c.value === chain);\n if (!selectedChain) {\n throw new Error('Invalid chain selection');\n }\n\n // Prepare platform options\n const platformChoices = selectedChain.supportedTemplates.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 2: Choose platform\n const secondStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n platform: {\n describe: 'Pick your platform',\n type: 'list',\n choices: platformChoices.map((c) => c.value)\n }\n });\n\n const { platform } = secondStep;\n\n const selectedTemplate = selectedChain.supportedTemplates.find((t) => t.value === platform);\n if (!selectedTemplate) {\n throw new Error('Invalid platform selection');\n }\n\n const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);\n const pkgManager = pkgInfo ? pkgInfo.name : 'npm';\n\n const sourceDir = path.join(\n __dirname,\n '..',\n 'templates',\n selectedTemplate.path.replace('{chain}', chain)\n );\n\n if (!(await exists(sourceDir))) {\n throw new Error(`Template directory not found: ${sourceDir}`);\n }\n\n const destDir = path.join(process.cwd(), projectName);\n if (await exists(destDir)) {\n throw new Error(`Target directory \"${destDir}\" already exists.`);\n }\n\n const files = await glob('**/*', { cwd: sourceDir, dot: true });\n\n for (const filename of files) {\n const sourceFile = path.join(sourceDir, filename);\n const destFile = path.join(destDir, filename);\n\n await fs.mkdir(path.dirname(destFile), { recursive: true });\n\n if (/package\\.json$/.test(sourceFile)) {\n const source = await fs.readFile(sourceFile, 'utf-8');\n await fs.writeFile(destFile, source.replaceAll(/{{dubhe-version}}/g, dubheVersion), 'utf-8');\n } else if (/\\.gitignore_$/.test(sourceFile)) {\n await fs.copyFile(sourceFile, destFile.replace(/_$/, ''));\n } else {\n await fs.copyFile(sourceFile, destFile);\n }\n }\n\n const cdProjectName = path.relative(cwd, destDir);\n\n const styles = {\n success: '\\x1b[32m%s\\x1b[0m',\n info: '\\x1b[36m%s\\x1b[0m',\n command: '\\x1b[33m%s\\x1b[0m',\n separator: '\\x1b[90m%s\\x1b[0m'\n };\n\n console.log('\\n' + '='.repeat(60));\n console.log(styles.success, '🎉 Project creation successful!');\n console.log(styles.info, `📁 Project location: ${destDir}`);\n console.log(styles.separator, '-'.repeat(60));\n console.log(styles.info, 'Next steps:\\n');\n\n if (destDir !== cwd) {\n console.log(\n styles.command,\n ` cd ${cdProjectName.includes(' ') ? `\"${cdProjectName}\"` : cdProjectName}`\n );\n }\n\n const actualTemplate = selectedTemplate.value;\n\n switch (actualTemplate) {\n case '101':\n case 'web':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n console.log(styles.command, ` ${pkgManager} run dev`);\n break;\n case 'contract':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n break;\n }\n\n console.log(styles.separator, '\\n' + '='.repeat(60) + '\\n');\n};\n\nfunction pkgFromUserAgent(userAgent: string | undefined) {\n if (!userAgent) return undefined;\n const pkgSpec = userAgent.split(' ')[0];\n const pkgSpecArr = pkgSpec.split('/');\n return {\n name: pkgSpecArr[0],\n version: pkgSpecArr[1]\n };\n}\n\ninit().catch((e) => {\n console.error(e);\n});\n","interface Template {\n title: string;\n description: string;\n value: string;\n path: string;\n}\n\ninterface Chain {\n title: string;\n description: string;\n value: string;\n supportedTemplates: Template[];\n}\n\nconst TEMPLATES = {\n QUICK_START: {\n title: '101',\n description: 'Quick start',\n value: '101',\n path: '101/{chain}-template'\n },\n WEB: {\n title: 'Web',\n description: 'Web template',\n value: 'web',\n path: 'nextjs/{chain}-template'\n },\n CONTRACT: {\n title: 'Contract',\n description: 'Contract template',\n value: 'contract',\n path: 'contract/{chain}-template'\n }\n} as const;\n\nexport const CHAINS: Chain[] = [\n {\n title: 'sui',\n description: 'Sui',\n value: 'sui',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'aptos',\n description: 'Aptos',\n value: 'aptos',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'rooch',\n description: 'Rooch',\n value: 'rooch',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'initia',\n description: 'Initia',\n value: 'initia',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'movement',\n description: 'Movement',\n value: 'movement',\n supportedTemplates: [TEMPLATES.QUICK_START]\n }\n];\n","{\n \"name\": \"create-dubhe\",\n \"version\": \"1.2.0-pre.124\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\n },\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"type\": \"module\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run type-check && pnpm run build:js\",\n \"build:js\": \"tsup && pnpm run copy-templates\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"cocos-js-build\": \"cd cocos-lib-builder && npm i && browserify aptos.js -p esmify > ../templates/cocos/aptos-template/assets/lib/dubhe.js && browserify sui.js -p esmify > ../templates/cocos/sui-template/assets/lib/dubhe.js\",\n \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"lint\": \"eslint . --ext .ts\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm lint && pnpm type-check\"\n },\n \"dependencies\": {\n \"browser-resolve\": \"^2.0.0\",\n \"browser-sync\": \"^2.29.3\",\n \"fast-glob\": \"^3.3.3\",\n \"yargs-interactive\": \"^3.0.1\"\n },\n \"devDependencies\": {\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"@types/yargs-interactive\": \"^2.1.6\",\n \"browserify\": \"^17.0.0\",\n \"cross-spawn\": \"^7.0.3\",\n \"eslint\": \"^9.0.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"esmify\": \"^2.1.1\",\n \"kolorist\": \"^1.7.0\",\n \"prettier\": \"3.3.3\",\n \"prompts\": \"^2.4.2\",\n \"typescript\": \"^5.8.3\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","import fs from 'node:fs/promises';\n\nexport async function exists(path: string) {\n try {\n await fs.access(path);\n return true;\n } catch {\n return false;\n }\n}\n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O,MAAM,+BAAwB,OAAO,EAAE;AAC1D,UAAQ,IAAI,OAAO,WAAW,IAAI,OAAO,EAAE,CAAC;AAC5C,UAAQ,IAAI,OAAO,MAAM,eAAe;AAExC,MAAI,YAAY,KAAK;AACnB,YAAQ;AAAA,MACN,OAAO;AAAA,MACP,QAAQ,cAAc,SAAS,GAAG,IAAI,IAAI,aAAa,MAAM,aAAa;AAAA,IAC5E;AAAA,EACF;AAEA,QAAM,iBAAiB,iBAAiB;AAExC,UAAQ,gBAAgB;AAAA,IACtB,KAAK;AAAA,IACL,KAAK;AACH,cAAQ,IAAI,OAAO,SAAS,KAAK,UAAU,UAAU;AACrD,cAAQ,IAAI,OAAO,SAAS,KAAK,UAAU,eAAe;AAC1D,cAAQ,IAAI,OAAO,SAAS,KAAK,UAAU,UAAU;AACrD;AAAA,IACF,KAAK;AACH,cAAQ,IAAI,OAAO,SAAS,KAAK,UAAU,UAAU;AACrD,cAAQ,IAAI,OAAO,SAAS,KAAK,UAAU,eAAe;AAC1D;AAAA,EACJ;AAEA,UAAQ,IAAI,OAAO,WAAW,OAAO,IAAI,OAAO,EAAE,IAAI,IAAI;AAC5D;AAEA,SAAS,iBAAiB,WAA+B;AACvD,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,UAAU,UAAU,MAAM,GAAG,EAAE,CAAC;AACtC,QAAM,aAAa,QAAQ,MAAM,GAAG;AACpC,SAAO;AAAA,IACL,MAAM,WAAW,CAAC;AAAA,IAClB,SAAS,WAAW,CAAC;AAAA,EACvB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACjB,CAAC;","names":["fs","path","fs"]}
|
package/package.json
CHANGED
package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move
CHANGED
|
@@ -8,10 +8,25 @@ module counter::dapp_key {
|
|
|
8
8
|
use sui::address;
|
|
9
9
|
use std::ascii::String;
|
|
10
10
|
|
|
11
|
-
///
|
|
11
|
+
/// DappKey — package-level authorization token for this DApp.
|
|
12
|
+
///
|
|
13
|
+
/// SECURITY: `new()` is intentionally `public(package)`.
|
|
14
|
+
/// Only code compiled into this package can construct a DappKey instance.
|
|
15
|
+
/// All framework write functions (`set_record`, `set_field`,
|
|
16
|
+
/// `take_record`, `create_user_storage`, …) require `_auth: DappKey`
|
|
17
|
+
/// as proof that the call originated from inside this package — an
|
|
18
|
+
/// external PTB cannot fabricate that proof.
|
|
19
|
+
///
|
|
20
|
+
/// NEVER change `new()` to `public`, and never accept a DappKey
|
|
21
|
+
/// value as a parameter from an external caller. Either mistake removes
|
|
22
|
+
/// every package-level access guard, allowing any PTB to write arbitrary
|
|
23
|
+
/// user data or register UserStorages without going through the DApp's
|
|
24
|
+
/// own entry functions.
|
|
12
25
|
|
|
13
26
|
public struct DappKey has copy, drop {}
|
|
14
27
|
|
|
28
|
+
/// Constructs an authorization token. Callable only from within this package.
|
|
29
|
+
/// Pass the result as `_auth` to any framework function that requires it.
|
|
15
30
|
public(package) fun new(): DappKey {
|
|
16
31
|
DappKey {}
|
|
17
32
|
}
|
|
@@ -6,17 +6,21 @@
|
|
|
6
6
|
module counter::user_storage_init {
|
|
7
7
|
use dubhe::dapp_service::{DappHub, DappStorage};
|
|
8
8
|
use dubhe::dapp_system;
|
|
9
|
+
use counter::dapp_key;
|
|
9
10
|
use counter::dapp_key::DappKey;
|
|
11
|
+
use counter::migrate;
|
|
10
12
|
|
|
11
13
|
/// Create a UserStorage for the transaction sender within this DApp.
|
|
12
14
|
/// Must be called once before the user can interact with any user-level resources.
|
|
13
|
-
/// Aborts if the DApp
|
|
15
|
+
/// Aborts if the DApp version does not match this package, the DApp is paused,
|
|
16
|
+
/// or the framework version has advanced.
|
|
14
17
|
#[allow(lint(public_entry))]
|
|
15
18
|
public entry fun init_user_storage(
|
|
16
19
|
dapp_hub: &DappHub,
|
|
17
20
|
dapp_storage: &mut DappStorage,
|
|
18
21
|
ctx: &mut TxContext,
|
|
19
22
|
) {
|
|
20
|
-
dapp_system::
|
|
23
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
24
|
+
dapp_system::create_user_storage(dapp_key::new(), dapp_hub, dapp_storage, ctx);
|
|
21
25
|
}
|
|
22
26
|
}
|
|
@@ -42,6 +42,6 @@ deps = { MoveStdlib = "MoveStdlib" }
|
|
|
42
42
|
|
|
43
43
|
[env.mainnet]
|
|
44
44
|
chain-id = "35834a8a"
|
|
45
|
-
original-published-id = "
|
|
46
|
-
latest-published-id = "
|
|
45
|
+
original-published-id = "0x6cb54e8bbcf59cc976584330689073500af755b12d85bf4f56d7eea9f232b8aa"
|
|
46
|
+
latest-published-id = "0x6cb54e8bbcf59cc976584330689073500af755b12d85bf4f56d7eea9f232b8aa"
|
|
47
47
|
published-version = "1"
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move
CHANGED
|
@@ -8,10 +8,25 @@ module dubhe::dapp_key {
|
|
|
8
8
|
use sui::address;
|
|
9
9
|
use std::ascii::String;
|
|
10
10
|
|
|
11
|
-
///
|
|
11
|
+
/// DappKey — package-level authorization token for this DApp.
|
|
12
|
+
///
|
|
13
|
+
/// SECURITY: `new()` is intentionally `public(package)`.
|
|
14
|
+
/// Only code compiled into this package can construct a DappKey instance.
|
|
15
|
+
/// All framework write functions (`set_record`, `set_field`,
|
|
16
|
+
/// `take_record`, `create_user_storage`, …) require `_auth: DappKey`
|
|
17
|
+
/// as proof that the call originated from inside this package — an
|
|
18
|
+
/// external PTB cannot fabricate that proof.
|
|
19
|
+
///
|
|
20
|
+
/// NEVER change `new()` to `public`, and never accept a DappKey
|
|
21
|
+
/// value as a parameter from an external caller. Either mistake removes
|
|
22
|
+
/// every package-level access guard, allowing any PTB to write arbitrary
|
|
23
|
+
/// user data or register UserStorages without going through the DApp's
|
|
24
|
+
/// own entry functions.
|
|
12
25
|
|
|
13
26
|
public struct DappKey has copy, drop {}
|
|
14
27
|
|
|
28
|
+
/// Constructs an authorization token. Callable only from within this package.
|
|
29
|
+
/// Pass the result as `_auth` to any framework function that requires it.
|
|
15
30
|
public(package) fun new(): DappKey {
|
|
16
31
|
DappKey {}
|
|
17
32
|
}
|
|
@@ -40,10 +40,6 @@ module dubhe::error {
|
|
|
40
40
|
const EUserDebtLimitExceeded: vector<u8> = b"User debt limit exceeded";
|
|
41
41
|
public fun user_debt_limit_exceeded(condition: bool) { assert!(condition, EUserDebtLimitExceeded) }
|
|
42
42
|
|
|
43
|
-
#[error]
|
|
44
|
-
const EDappSuspended: vector<u8> = b"Dapp is suspended";
|
|
45
|
-
public fun dapp_suspended(condition: bool) { assert!(condition, EDappSuspended) }
|
|
46
|
-
|
|
47
43
|
#[error]
|
|
48
44
|
const EDappKeyMismatch: vector<u8> = b"Dapp key mismatch";
|
|
49
45
|
public fun dapp_key_mismatch(condition: bool) { assert!(condition, EDappKeyMismatch) }
|
|
@@ -56,10 +52,6 @@ module dubhe::error {
|
|
|
56
52
|
const ENotCanonicalOwner: vector<u8> = b"Not canonical owner";
|
|
57
53
|
public fun not_canonical_owner(condition: bool) { assert!(condition, ENotCanonicalOwner) }
|
|
58
54
|
|
|
59
|
-
#[error]
|
|
60
|
-
const EInsufficientCreditToUnsuspend: vector<u8> = b"Insufficient credit to unsuspend";
|
|
61
|
-
public fun insufficient_credit_to_unsuspend(condition: bool) { assert!(condition, EInsufficientCreditToUnsuspend) }
|
|
62
|
-
|
|
63
55
|
#[error]
|
|
64
56
|
const EUserStorageAlreadyExists: vector<u8> = b"User storage already exists";
|
|
65
57
|
public fun user_storage_already_exists(condition: bool) { assert!(condition, EUserStorageAlreadyExists) }
|
|
@@ -104,14 +96,6 @@ module dubhe::error {
|
|
|
104
96
|
const ENotSceneParticipant: vector<u8> = b"Not a scene participant";
|
|
105
97
|
public fun not_scene_participant(condition: bool) { assert!(condition, ENotSceneParticipant) }
|
|
106
98
|
|
|
107
|
-
#[error]
|
|
108
|
-
const ENonceAlreadyUsed: vector<u8> = b"Nonce already used";
|
|
109
|
-
public fun nonce_already_used(condition: bool) { assert!(condition, ENonceAlreadyUsed) }
|
|
110
|
-
|
|
111
|
-
#[error]
|
|
112
|
-
const EInvalidConsentSignature: vector<u8> = b"Invalid consent signature";
|
|
113
|
-
public fun invalid_consent_signature(condition: bool) { assert!(condition, EInvalidConsentSignature) }
|
|
114
|
-
|
|
115
99
|
#[error]
|
|
116
100
|
const EEntityNotFound: vector<u8> = b"Entity not found";
|
|
117
101
|
public fun entity_not_found(condition: bool) { assert!(condition, EEntityNotFound) }
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move
CHANGED
|
@@ -33,9 +33,9 @@ module dubhe::dapp_service {
|
|
|
33
33
|
// ─── PermitMetadata — authorization token for reactive writes ─────────────
|
|
34
34
|
//
|
|
35
35
|
// Embedded in every codegen-generated typed SceneStorage struct.
|
|
36
|
-
// Reactive write functions require a
|
|
37
|
-
//
|
|
38
|
-
//
|
|
36
|
+
// Reactive write functions require a &ScenePermit<T> to verify that both
|
|
37
|
+
// the initiator and the target are registered participants and that the
|
|
38
|
+
// scene is still active.
|
|
39
39
|
//
|
|
40
40
|
// Participants are stored as dynamic fields on the scene object's UID
|
|
41
41
|
// (key = ParticipantKey { addr }, value = bool true). This gives O(1)
|
|
@@ -56,7 +56,7 @@ module dubhe::dapp_service {
|
|
|
56
56
|
/// None = invitations never expire. Once passed, accept_<scene> aborts.
|
|
57
57
|
invites_expire_at: Option<u64>,
|
|
58
58
|
/// Maximum number of confirmed participants allowed in this scene.
|
|
59
|
-
/// None = unlimited. Enforced
|
|
59
|
+
/// None = unlimited. Enforced on participant add.
|
|
60
60
|
max_participants: Option<u64>,
|
|
61
61
|
/// Current confirmed participant count — updated by add/remove.
|
|
62
62
|
participant_count: u64,
|
|
@@ -114,36 +114,6 @@ module dubhe::dapp_service {
|
|
|
114
114
|
meta.invitees.contains(&addr)
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
/// Moves `addr` from the invitees list into the confirmed participants list.
|
|
118
|
-
/// Aborts if addr is not in invitees.
|
|
119
|
-
public fun accept_scene_invitation_meta(id: &mut UID, meta: &mut PermitMetadata, addr: address) {
|
|
120
|
-
let (found, idx) = meta.invitees.index_of(&addr);
|
|
121
|
-
error::not_participant(found);
|
|
122
|
-
meta.invitees.remove(idx);
|
|
123
|
-
add_scene_participant(id, meta, addr);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/// Add `addr` as a confirmed participant (O(1) dynamic field write).
|
|
127
|
-
/// Enforces max_participants cap if set. No-op if already a participant.
|
|
128
|
-
public fun add_scene_participant(id: &mut UID, meta: &mut PermitMetadata, addr: address) {
|
|
129
|
-
if (dynamic_field::exists_(id, ParticipantKey { addr })) { return };
|
|
130
|
-
if (meta.max_participants.is_some()) {
|
|
131
|
-
error::scene_full(
|
|
132
|
-
meta.participant_count < *option::borrow(&meta.max_participants)
|
|
133
|
-
);
|
|
134
|
-
};
|
|
135
|
-
dynamic_field::add(id, ParticipantKey { addr }, true);
|
|
136
|
-
meta.participant_count = meta.participant_count + 1;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/// Remove `addr` from confirmed participants (O(1) dynamic field remove).
|
|
140
|
-
/// No-op if not a participant.
|
|
141
|
-
public fun remove_scene_participant(id: &mut UID, meta: &mut PermitMetadata, addr: address) {
|
|
142
|
-
if (!dynamic_field::exists_(id, ParticipantKey { addr })) { return };
|
|
143
|
-
let _: bool = dynamic_field::remove(id, ParticipantKey { addr });
|
|
144
|
-
meta.participant_count = meta.participant_count - 1;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
117
|
/// O(1) participant check via dynamic field existence.
|
|
148
118
|
public fun is_scene_participant(id: &UID, addr: address): bool {
|
|
149
119
|
dynamic_field::exists_(id, ParticipantKey { addr })
|
|
@@ -189,6 +159,7 @@ module dubhe::dapp_service {
|
|
|
189
159
|
};
|
|
190
160
|
}
|
|
191
161
|
|
|
162
|
+
#[test_only]
|
|
192
163
|
public fun has_object_entity_id(
|
|
193
164
|
ds: &DappStorage,
|
|
194
165
|
type_tag: vector<u8>,
|
|
@@ -197,6 +168,7 @@ module dubhe::dapp_service {
|
|
|
197
168
|
dynamic_field::exists_(&ds.id, ObjectEntityIdKey { type_tag, entity_id })
|
|
198
169
|
}
|
|
199
170
|
|
|
171
|
+
#[test_only]
|
|
200
172
|
public fun get_object_entity_id(
|
|
201
173
|
ds: &DappStorage,
|
|
202
174
|
type_tag: vector<u8>,
|
|
@@ -535,7 +507,7 @@ module dubhe::dapp_service {
|
|
|
535
507
|
let mut i = 0;
|
|
536
508
|
let len = participants.length();
|
|
537
509
|
while (i < len) {
|
|
538
|
-
|
|
510
|
+
add_participant_in_scene_permit(&mut permit, *participants.borrow(i));
|
|
539
511
|
i = i + 1;
|
|
540
512
|
};
|
|
541
513
|
let permit_id = object::uid_to_address(&permit.id);
|
|
@@ -933,11 +905,17 @@ module dubhe::dapp_service {
|
|
|
933
905
|
};
|
|
934
906
|
}
|
|
935
907
|
|
|
908
|
+
/// Return the full fee-change history ring buffer (most recent at the back).
|
|
909
|
+
/// Useful for off-chain explorers and billing tools that need to determine
|
|
910
|
+
/// the applicable fee rate for a historical write operation.
|
|
936
911
|
public fun fee_history(cfg: &FrameworkFeeConfig): &vector<FeeHistoryEntry> {
|
|
937
912
|
&cfg.fee_history
|
|
938
913
|
}
|
|
914
|
+
/// Base fee that was committed in this history entry (MIST per write).
|
|
939
915
|
public fun fee_history_base_fee(e: &FeeHistoryEntry): u256 { e.base_fee }
|
|
916
|
+
/// Bytes fee that was committed in this history entry (MIST per byte).
|
|
940
917
|
public fun fee_history_bytes_fee(e: &FeeHistoryEntry): u256 { e.bytes_fee }
|
|
918
|
+
/// Epoch-ms timestamp from which this history entry's rates became effective.
|
|
941
919
|
public fun fee_history_effective_from_ms(e: &FeeHistoryEntry): u64 { e.effective_from_ms }
|
|
942
920
|
|
|
943
921
|
public fun is_fee_config_initialized(dh: &DappHub): bool {
|
|
@@ -1823,4 +1801,42 @@ module dubhe::dapp_service {
|
|
|
1823
1801
|
object::delete(id);
|
|
1824
1802
|
}
|
|
1825
1803
|
|
|
1804
|
+
#[test_only]
|
|
1805
|
+
public fun create_scene_permit_for_testing<DappKey: copy + drop, PermType>(
|
|
1806
|
+
participants: vector<address>,
|
|
1807
|
+
expires_at: std::option::Option<u64>,
|
|
1808
|
+
max_participants: std::option::Option<u64>,
|
|
1809
|
+
ctx: &mut TxContext,
|
|
1810
|
+
): ScenePermit<PermType> {
|
|
1811
|
+
let mut permit = ScenePermit<PermType> {
|
|
1812
|
+
id: object::new(ctx),
|
|
1813
|
+
dapp_key: type_name::with_defining_ids<DappKey>().into_string(),
|
|
1814
|
+
permit_type: b"test",
|
|
1815
|
+
meta: new_scene_meta(expires_at, max_participants),
|
|
1816
|
+
};
|
|
1817
|
+
participants.do!(|addr| { add_participant_in_scene_permit(&mut permit, addr) });
|
|
1818
|
+
permit
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
#[test_only]
|
|
1822
|
+
public fun create_scene_permit_with_invitations_for_testing<DappKey: copy + drop, PermType>(
|
|
1823
|
+
invitees: vector<address>,
|
|
1824
|
+
invites_expire_at: std::option::Option<u64>,
|
|
1825
|
+
expires_at: std::option::Option<u64>,
|
|
1826
|
+
ctx: &mut TxContext,
|
|
1827
|
+
): ScenePermit<PermType> {
|
|
1828
|
+
ScenePermit<PermType> {
|
|
1829
|
+
id: object::new(ctx),
|
|
1830
|
+
dapp_key: type_name::with_defining_ids<DappKey>().into_string(),
|
|
1831
|
+
permit_type: b"test",
|
|
1832
|
+
meta: new_scene_meta_with_invitations(invitees, invites_expire_at, expires_at, option::none()),
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
#[test_only]
|
|
1837
|
+
public fun destroy_scene_permit_for_testing<PermType>(permit: ScenePermit<PermType>) {
|
|
1838
|
+
let ScenePermit { id, dapp_key: _, permit_type: _, meta: _ } = permit;
|
|
1839
|
+
object::delete(id);
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1826
1842
|
}
|