create-dubhe 1.2.0-pre.55 → 1.2.0-pre.57
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/dubhe/Move.lock +6 -23
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +16 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +6 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/asset_account.move +33 -17
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/asset_metadata.move +97 -81
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/asset_pools.move +36 -20
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/bridge_config.move +48 -32
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/bridge_deposit.move +43 -31
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/bridge_withdraw.move +44 -32
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +28 -16
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +57 -41
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +121 -105
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_proxy.move +208 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_asset_id.move +24 -12
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +30 -18
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/wrapper_assets.move +36 -20
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +76 -29
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +20 -17
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/events.move +19 -12
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/table_metadata.move +42 -18
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +11 -10
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/assets/assets.move +12 -11
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/assets/functions.move +5 -4
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/bridge.move +3 -2
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +151 -56
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dex/dex.move +4 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dex/functions.move +4 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/entity_id.move +3 -2
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/gov.move +7 -6
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/wrapper.move +4 -4
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/assets.move +17 -16
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/bcs.move +16 -0
- package/templates/contract/sui-template/src/dubhe/Move.lock +6 -23
- package/templates/contract/sui-template/src/dubhe/sources/codegen/errors.move +16 -0
- package/templates/contract/sui-template/src/dubhe/sources/codegen/genesis.move +6 -1
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/asset_account.move +33 -17
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/asset_metadata.move +97 -81
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/asset_pools.move +36 -20
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/bridge_config.move +48 -32
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/bridge_deposit.move +43 -31
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/bridge_withdraw.move +44 -32
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_config.move +28 -16
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_state.move +57 -41
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_metadata.move +121 -105
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_proxy.move +208 -0
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dubhe_asset_id.move +24 -12
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dubhe_config.move +30 -18
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/wrapper_assets.move +36 -20
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_service.move +76 -29
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_store.move +20 -17
- package/templates/contract/sui-template/src/dubhe/sources/core/events.move +19 -12
- package/templates/contract/sui-template/src/dubhe/sources/core/table_metadata.move +42 -18
- package/templates/contract/sui-template/src/dubhe/sources/scripts/deploy_hook.move +11 -10
- package/templates/contract/sui-template/src/dubhe/sources/systems/assets/assets.move +12 -11
- package/templates/contract/sui-template/src/dubhe/sources/systems/assets/functions.move +5 -4
- package/templates/contract/sui-template/src/dubhe/sources/systems/bridge.move +3 -2
- package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +151 -56
- package/templates/contract/sui-template/src/dubhe/sources/systems/dex/dex.move +4 -3
- package/templates/contract/sui-template/src/dubhe/sources/systems/dex/functions.move +4 -3
- package/templates/contract/sui-template/src/dubhe/sources/systems/entity_id.move +3 -2
- package/templates/contract/sui-template/src/dubhe/sources/systems/gov.move +7 -6
- package/templates/contract/sui-template/src/dubhe/sources/systems/wrapper.move +4 -4
- package/templates/contract/sui-template/src/dubhe/sources/tests/assets.move +17 -16
- package/templates/contract/sui-template/src/dubhe/sources/utils/bcs.move +16 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.lock +6 -23
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +16 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +6 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/asset_account.move +33 -17
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/asset_metadata.move +97 -81
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/asset_pools.move +36 -20
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/bridge_config.move +48 -32
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/bridge_deposit.move +43 -31
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/bridge_withdraw.move +44 -32
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +28 -16
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +57 -41
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +121 -105
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_proxy.move +208 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_asset_id.move +24 -12
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +30 -18
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/wrapper_assets.move +36 -20
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +76 -29
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +20 -17
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/events.move +19 -12
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/table_metadata.move +42 -18
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +11 -10
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/assets/assets.move +12 -11
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/assets/functions.move +5 -4
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/bridge.move +3 -2
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +151 -56
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dex/dex.move +4 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dex/functions.move +4 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/entity_id.move +3 -2
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/gov.move +7 -6
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/wrapper.move +4 -4
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/assets.move +17 -16
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/bcs.move +16 -0
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 defaultTargetDir = 'dubhe-template-project';\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.55\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"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 \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\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 \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm type-check\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\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/yargs-interactive\": \"^2.1.6\",\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"cross-spawn\": \"^7.0.3\",\n \"kolorist\": \"^1.7.0\",\n \"prompts\": \"^2.4.2\",\n \"tsc\": \"^2.0.4\",\n \"esmify\": \"^2.1.1\",\n \"browserify\": \"^17.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"prettier\": \"3.3.3\"\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;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,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"]}
|
|
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 defaultTargetDir = 'dubhe-template-project';\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.57\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"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 \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\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 \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm type-check\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\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/yargs-interactive\": \"^2.1.6\",\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"cross-spawn\": \"^7.0.3\",\n \"kolorist\": \"^1.7.0\",\n \"prompts\": \"^2.4.2\",\n \"tsc\": \"^2.0.4\",\n \"esmify\": \"^2.1.1\",\n \"browserify\": \"^17.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"prettier\": \"3.3.3\"\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,oBAAoB,CAAC,UAAU,WAAW;AAAA,EAC5C;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,WAAW;AAAA,EAC5C;AACF;;;AClEA;AAAA,EACE,MAAQ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
flavor = "sui"
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
[env.testnet]
|
|
30
|
-
chain-id = "4c78adac"
|
|
31
|
-
original-published-id = "0xe2a38ae55a486bcaf79658cde76894207cada4d64d3cb1b2b06c6c12c10d5d5b"
|
|
32
|
-
latest-published-id = "0xa6477a6bf50e2389383b34a76d59ccfbec766ff2decefe38e1d8436ef8a9b245"
|
|
33
|
-
published-version = "3"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
29
|
[env.localnet]
|
|
53
30
|
chain-id = "7b439c64"
|
|
54
31
|
original-published-id = "0x4727fa99ca6aa1f426572107ba49a39ee266a6e60d4891d1c8039fb76bfa423b"
|
|
55
32
|
latest-published-id = "0x3fd12dfbd15beb9dfb34b01022cd86b55d35fca7a570dd3309635a2e37b5c8b1"
|
|
56
33
|
published-version = "2"
|
|
34
|
+
|
|
35
|
+
[env.testnet]
|
|
36
|
+
chain-id = "4c78adac"
|
|
37
|
+
original-published-id = "0x4805b1fee654164754e222a617e8ee0eefcc858bf194305a9832582c23c7bc0d"
|
|
38
|
+
latest-published-id = "0x4805b1fee654164754e222a617e8ee0eefcc858bf194305a9832582c23c7bc0d"
|
|
39
|
+
published-version = "1"
|
|
@@ -253,4 +253,20 @@
|
|
|
253
253
|
public fun insufficient_credit_error(condition: bool) {
|
|
254
254
|
assert!(condition, INSUFFICIENT_CREDIT)
|
|
255
255
|
}
|
|
256
|
+
|
|
257
|
+
#[error]
|
|
258
|
+
|
|
259
|
+
const DAPP_NOT_BEEN_DELEGATED: vector<u8> = b"Dapp not been delegated";
|
|
260
|
+
|
|
261
|
+
public fun dapp_not_been_delegated_error(condition: bool) {
|
|
262
|
+
assert!(condition, DAPP_NOT_BEEN_DELEGATED)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
#[error]
|
|
266
|
+
|
|
267
|
+
const DAPP_ALREADY_DELEGATED: vector<u8> = b"Dapp already delegated";
|
|
268
|
+
|
|
269
|
+
public fun dapp_already_delegated_error(condition: bool) {
|
|
270
|
+
assert!(condition, DAPP_ALREADY_DELEGATED)
|
|
271
|
+
}
|
|
256
272
|
}
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
use dubhe::dapp_system;
|
|
10
10
|
|
|
11
|
+
use std::ascii::string;
|
|
12
|
+
|
|
11
13
|
use dubhe::dubhe_asset_id;
|
|
12
14
|
|
|
13
15
|
use dubhe::dubhe_config;
|
|
@@ -32,10 +34,12 @@
|
|
|
32
34
|
|
|
33
35
|
use dubhe::dapp_fee_state;
|
|
34
36
|
|
|
37
|
+
use dubhe::dapp_proxy;
|
|
38
|
+
|
|
35
39
|
public entry fun run(dapp_hub: &mut DappHub, clock: &Clock, ctx: &mut TxContext) {
|
|
36
40
|
// Create Dapp
|
|
37
41
|
let dapp_key = dapp_key::new();
|
|
38
|
-
dapp_system::create_dapp(dapp_hub, dapp_key, b"dubhe", b"Dubhe Protocol", clock, ctx);
|
|
42
|
+
dapp_system::create_dapp(dapp_hub, dapp_key, string(b"dubhe"), string(b"Dubhe Protocol"), clock, ctx);
|
|
39
43
|
// Register tables
|
|
40
44
|
dubhe_asset_id::register_table(dapp_hub, ctx);
|
|
41
45
|
dubhe_config::register_table(dapp_hub, ctx);
|
|
@@ -49,6 +53,7 @@
|
|
|
49
53
|
dapp_metadata::register_table(dapp_hub, ctx);
|
|
50
54
|
dapp_fee_config::register_table(dapp_hub, ctx);
|
|
51
55
|
dapp_fee_state::register_table(dapp_hub, ctx);
|
|
56
|
+
dapp_proxy::register_table(dapp_hub, ctx);
|
|
52
57
|
// Logic that needs to be automated once the contract is deployed
|
|
53
58
|
dubhe::deploy_hook::run(dapp_hub, ctx);
|
|
54
59
|
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
use sui::bcs::{to_bytes};
|
|
10
10
|
|
|
11
|
+
use std::ascii::{string, String, into_bytes};
|
|
12
|
+
|
|
11
13
|
use dubhe::table_id;
|
|
12
14
|
|
|
13
15
|
use dubhe::dapp_service::{Self, DappHub};
|
|
@@ -24,6 +26,10 @@
|
|
|
24
26
|
|
|
25
27
|
const TABLE_NAME: vector<u8> = b"asset_account";
|
|
26
28
|
|
|
29
|
+
const TABLE_TYPE: vector<u8> = b"Resource";
|
|
30
|
+
|
|
31
|
+
const OFFCHAIN: bool = false;
|
|
32
|
+
|
|
27
33
|
public struct AssetAccount has copy, drop, store {
|
|
28
34
|
balance: u256,
|
|
29
35
|
status: AccountStatus,
|
|
@@ -52,36 +58,46 @@
|
|
|
52
58
|
self.status = status
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
public fun get_table_id():
|
|
56
|
-
|
|
61
|
+
public fun get_table_id(): String {
|
|
62
|
+
string(TABLE_NAME)
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
public fun get_key_schemas(): vector<
|
|
60
|
-
vector[b"address",
|
|
65
|
+
public fun get_key_schemas(): vector<String> {
|
|
66
|
+
vector[string(b"address"),
|
|
67
|
+
string(b"address")
|
|
68
|
+
]
|
|
61
69
|
}
|
|
62
70
|
|
|
63
|
-
public fun get_value_schemas(): vector<
|
|
64
|
-
vector[b"u256",
|
|
71
|
+
public fun get_value_schemas(): vector<String> {
|
|
72
|
+
vector[string(b"u256"),
|
|
73
|
+
string(b"AccountStatus")
|
|
74
|
+
]
|
|
65
75
|
}
|
|
66
76
|
|
|
67
|
-
public fun get_key_names(): vector<
|
|
68
|
-
vector[b"asset_id",
|
|
77
|
+
public fun get_key_names(): vector<String> {
|
|
78
|
+
vector[string(b"asset_id"),
|
|
79
|
+
string(b"account")
|
|
80
|
+
]
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
public fun get_value_names(): vector<
|
|
72
|
-
vector[b"balance",
|
|
83
|
+
public fun get_value_names(): vector<String> {
|
|
84
|
+
vector[string(b"balance"),
|
|
85
|
+
string(b"status")
|
|
86
|
+
]
|
|
73
87
|
}
|
|
74
88
|
|
|
75
89
|
public(package) fun register_table(dapp_hub: &mut DappHub, ctx: &mut TxContext) {
|
|
76
90
|
let dapp_key = dapp_key::new();
|
|
77
91
|
dapp_service::register_table(
|
|
78
|
-
dapp_hub,
|
|
79
|
-
|
|
92
|
+
dapp_hub,
|
|
93
|
+
dapp_key,
|
|
94
|
+
string(TABLE_TYPE),
|
|
80
95
|
get_table_id(),
|
|
81
96
|
get_key_schemas(),
|
|
82
97
|
get_key_names(),
|
|
83
98
|
get_value_schemas(),
|
|
84
99
|
get_value_names(),
|
|
100
|
+
OFFCHAIN,
|
|
85
101
|
ctx
|
|
86
102
|
);
|
|
87
103
|
}
|
|
@@ -111,7 +127,7 @@
|
|
|
111
127
|
let mut key_tuple = vector::empty();
|
|
112
128
|
key_tuple.push_back(to_bytes(&asset_id));
|
|
113
129
|
key_tuple.push_back(to_bytes(&account));
|
|
114
|
-
dapp_service::delete_record<DappKey>(dapp_hub, dapp_key::new(), get_table_id(), key_tuple);
|
|
130
|
+
dapp_service::delete_record<DappKey>(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, OFFCHAIN);
|
|
115
131
|
}
|
|
116
132
|
|
|
117
133
|
public fun get_balance(dapp_hub: &DappHub, asset_id: address, account: address): u256 {
|
|
@@ -129,7 +145,7 @@
|
|
|
129
145
|
key_tuple.push_back(to_bytes(&asset_id));
|
|
130
146
|
key_tuple.push_back(to_bytes(&account));
|
|
131
147
|
let value = to_bytes(&balance);
|
|
132
|
-
dapp_service::set_field(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, 0, value);
|
|
148
|
+
dapp_service::set_field(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, 0, value, OFFCHAIN);
|
|
133
149
|
}
|
|
134
150
|
|
|
135
151
|
public fun get_status(dapp_hub: &DappHub, asset_id: address, account: address): AccountStatus {
|
|
@@ -147,7 +163,7 @@
|
|
|
147
163
|
key_tuple.push_back(to_bytes(&asset_id));
|
|
148
164
|
key_tuple.push_back(to_bytes(&account));
|
|
149
165
|
let value = dubhe::account_status::encode(status);
|
|
150
|
-
dapp_service::set_field(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, 1, value);
|
|
166
|
+
dapp_service::set_field(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, 1, value, OFFCHAIN);
|
|
151
167
|
}
|
|
152
168
|
|
|
153
169
|
public fun get(dapp_hub: &DappHub, asset_id: address, account: address): (u256, AccountStatus) {
|
|
@@ -172,7 +188,7 @@
|
|
|
172
188
|
key_tuple.push_back(to_bytes(&asset_id));
|
|
173
189
|
key_tuple.push_back(to_bytes(&account));
|
|
174
190
|
let value_tuple = encode(balance, status);
|
|
175
|
-
dapp_service::set_record(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, value_tuple);
|
|
191
|
+
dapp_service::set_record(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, value_tuple, OFFCHAIN);
|
|
176
192
|
}
|
|
177
193
|
|
|
178
194
|
public fun get_struct(dapp_hub: &DappHub, asset_id: address, account: address): AssetAccount {
|
|
@@ -193,7 +209,7 @@
|
|
|
193
209
|
key_tuple.push_back(to_bytes(&asset_id));
|
|
194
210
|
key_tuple.push_back(to_bytes(&account));
|
|
195
211
|
let value_tuple = encode_struct(asset_account);
|
|
196
|
-
dapp_service::set_record(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, value_tuple);
|
|
212
|
+
dapp_service::set_record(dapp_hub, dapp_key::new(), get_table_id(), key_tuple, value_tuple, OFFCHAIN);
|
|
197
213
|
}
|
|
198
214
|
|
|
199
215
|
public fun encode(balance: u256, status: AccountStatus): vector<vector<u8>> {
|