create-dubhe 0.0.4 → 0.0.5
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/index.mjs +44 -42
- package/package.json +1 -1
- package/template/101/rooch-template/.dockerignore +7 -0
- package/template/101/rooch-template/.eslintrc.json +3 -0
- package/template/101/rooch-template/.prettierrc +8 -0
- package/template/101/rooch-template/Dockerfile +52 -0
- package/template/101/rooch-template/LICENSE +674 -0
- package/template/101/rooch-template/README.md +14 -0
- package/template/101/rooch-template/contracts/counter/Move.toml +14 -0
- package/template/101/rooch-template/contracts/counter/sources/counter.move +48 -0
- package/template/101/rooch-template/dubhe.config.ts +14 -0
- package/template/101/rooch-template/jest.config.ts +17 -0
- package/template/101/rooch-template/next-env.d.ts +5 -0
- package/template/101/rooch-template/next-i18next.config.js +6 -0
- package/template/101/rooch-template/next.config.js +15 -0
- package/template/101/rooch-template/package.json +72 -0
- package/template/101/rooch-template/postcss.config.js +6 -0
- package/template/101/rooch-template/public/discord.svg +9 -0
- package/template/101/rooch-template/public/fail.svg +12 -0
- package/template/101/rooch-template/public/favicon.ico +0 -0
- package/template/101/rooch-template/public/locales/de/common.json +8 -0
- package/template/101/rooch-template/public/locales/de/footer.json +3 -0
- package/template/101/rooch-template/public/locales/de/second-page.json +5 -0
- package/template/101/rooch-template/public/locales/en/common.json +8 -0
- package/template/101/rooch-template/public/locales/en/footer.json +3 -0
- package/template/101/rooch-template/public/locales/en/second-page.json +5 -0
- package/template/101/rooch-template/public/locales/zn/common.json +8 -0
- package/template/101/rooch-template/public/locales/zn/footer.json +3 -0
- package/template/101/rooch-template/public/locales/zn/second-page.json +5 -0
- package/template/101/rooch-template/public/logo.svg +1 -0
- package/template/101/rooch-template/public/medium.svg +9 -0
- package/template/101/rooch-template/public/successful.svg +11 -0
- package/template/101/rooch-template/public/telegram.svg +9 -0
- package/template/101/rooch-template/public/twitter.svg +9 -0
- package/template/101/rooch-template/scripts/checkBalance.ts +37 -0
- package/template/101/rooch-template/scripts/generateAccount.ts +55 -0
- package/template/101/rooch-template/scripts/storeConfig.ts +52 -0
- package/template/101/rooch-template/scripts/waitNode.ts +9 -0
- package/template/101/rooch-template/src/chain/config.ts +5 -0
- package/template/101/rooch-template/src/css/font-awesome.css +2337 -0
- package/template/101/rooch-template/src/css/font-awesome.min.css +4 -0
- package/template/101/rooch-template/src/fonts/FontAwesome.otf +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.eot +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.svg +2671 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.ttf +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.woff +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.woff2 +0 -0
- package/template/101/rooch-template/src/jotai/index.tsx +12 -0
- package/template/101/rooch-template/src/pages/_app.tsx +9 -0
- package/template/101/rooch-template/src/pages/home/index.tsx +82 -0
- package/template/101/rooch-template/src/pages/index.tsx +14 -0
- package/template/101/rooch-template/tailwind.config.js +56 -0
- package/template/101/rooch-template/tsconfig.json +25 -0
- package/template/101/sui-template/contracts/counter/Move.toml +3 -3
- package/template/101/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +17 -15
- package/template/101/sui-template/contracts/counter/sources/script/deploy_hook.move +37 -19
- package/template/101/sui-template/contracts/counter/sources/script/migrate.move +8 -0
- package/template/101/sui-template/localnet/dubhe-framework/Move.toml +6 -16
- package/template/{nextjs/sui-template/localnet/dubhe-framework/sources/schemas/dapps/dapps.move → 101/sui-template/localnet/dubhe-framework/sources/core/dapps/schema.move} +12 -2
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +0 -3
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/map.move +0 -3
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/value.move +0 -3
- package/template/101/sui-template/package.json +19 -27
- package/template/101/sui-template/scripts/deployment/testnet/deploy.ts +2 -2
- package/template/101/sui-template/src/chain/config.ts +3 -3
- package/template/cocos/sui-template/assets/lib/dubhe.js +21 -1
- package/template/cocos/sui-template/contracts/counter/Move.toml +1 -1
- package/template/cocos/sui-template/package.json +3 -3
- package/template/contract/sui-template/contracts/counter/Move.toml +13 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/dapp_key.move +16 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move +60 -0
- package/template/contract/sui-template/contracts/counter/sources/script/deploy_hook.move +85 -0
- package/template/contract/sui-template/contracts/counter/sources/script/migrate.move +8 -0
- package/template/contract/sui-template/dubhe.config.ts +14 -0
- package/template/contract/sui-template/localnet/dubhe-framework/Move.toml +29 -0
- package/template/{101/sui-template/localnet/dubhe-framework/sources/schemas/dapps/dapps.move → contract/sui-template/localnet/dubhe-framework/sources/core/dapps/schema.move} +12 -2
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +153 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/map.move +156 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/value.move +97 -0
- package/template/contract/sui-template/localnet/dubhe-framework/tests/init.move +6 -0
- package/template/contract/sui-template/localnet/dubhe-framework/tests/obelisk_framework_tests.move +19 -0
- package/template/contract/sui-template/package.json +28 -0
- package/template/contract/sui-template/scripts/checkBalance.ts +40 -0
- package/template/contract/sui-template/scripts/deployment/common.ts +45 -0
- package/template/contract/sui-template/scripts/deployment/localnet/deploy.ts +42 -0
- package/template/contract/sui-template/scripts/deployment/testnet/deploy.ts +48 -0
- package/template/contract/sui-template/scripts/deployment/types.ts +13 -0
- package/template/contract/sui-template/scripts/framework/common.ts +17 -0
- package/template/contract/sui-template/scripts/framework/deploy.ts +199 -0
- package/template/contract/sui-template/scripts/framework/parse-history.ts +76 -0
- package/template/contract/sui-template/scripts/framework/types.ts +8 -0
- package/template/contract/sui-template/scripts/generateAccount.ts +37 -0
- package/template/contract/sui-template/tsconfig.json +35 -0
- package/template/nextjs/sui-template/contracts/counter/Move.toml +3 -3
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +17 -15
- package/template/nextjs/sui-template/contracts/counter/sources/script/deploy_hook.move +37 -19
- package/template/nextjs/sui-template/contracts/counter/sources/script/migrate.move +8 -0
- package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +11 -0
- package/template/nextjs/sui-template/dubhe.config.ts +2 -2
- package/template/nextjs/sui-template/localnet/dubhe-framework/Move.toml +6 -16
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/metadata.move +96 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/schema.move +83 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +0 -3
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/map.move +0 -3
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/tests.move +398 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/value.move +0 -3
- package/template/nextjs/sui-template/package.json +19 -27
- package/template/nextjs/sui-template/scripts/deployment/testnet/deploy.ts +2 -2
- package/template/nextjs/sui-template/src/chain/config.ts +2 -2
- package/template/101/sui-template/localnet/dubhe-framework/README.md +0 -18
- package/template/101/sui-template/localnet/dubhe-framework/sources/access_control.move +0 -35
- package/template/101/sui-template/localnet/dubhe-framework/sources/events.move +0 -23
- package/template/101/sui-template/localnet/dubhe-framework/sources/resource_id.move +0 -22
- package/template/101/sui-template/localnet/dubhe-framework/sources/resource_types.move +0 -18
- package/template/101/sui-template/localnet/dubhe-framework/sources/schema.move +0 -36
- package/template/101/sui-template/localnet/dubhe-framework/sources/systems/dapps.move +0 -90
- package/template/101/sui-template/localnet/dubhe-framework/sources/world.move +0 -81
- package/template/101/sui-template/localnet/dubhe-framework/tests/dapp.move +0 -16
- package/template/nextjs/sui-template/localnet/dubhe-framework/README.md +0 -18
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/access_control.move +0 -35
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/events.move +0 -23
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/resource_id.move +0 -22
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/resource_types.move +0 -18
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/schema.move +0 -36
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/systems/dapps.move +0 -90
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/world.move +0 -81
- package/template/nextjs/sui-template/localnet/dubhe-framework/tests/dapp.move +0 -16
- /package/template/101/sui-template/contracts/counter/sources/{system → systems}/counter.move +0 -0
- /package/template/101/sui-template/localnet/dubhe-framework/sources/{schemas → core}/dapps/metadata.move +0 -0
- /package/template/101/sui-template/localnet/dubhe-framework/{tests/storage.move → sources/storages/tests.move} +0 -0
- /package/template/{nextjs/sui-template/contracts/counter/sources/system → contract/sui-template/contracts/counter/sources/systems}/counter.move +0 -0
- /package/template/{nextjs/sui-template/localnet/dubhe-framework/sources/schemas → contract/sui-template/localnet/dubhe-framework/sources/core}/dapps/metadata.move +0 -0
- /package/template/{nextjs/sui-template/localnet/dubhe-framework/tests/storage.move → contract/sui-template/localnet/dubhe-framework/sources/storages/tests.move} +0 -0
package/template/contract/sui-template/localnet/dubhe-framework/tests/obelisk_framework_tests.move
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
#[test_only]
|
|
3
|
+
module dubhe_framework::dubhe_framework_tests {
|
|
4
|
+
// uncomment this line to import the module
|
|
5
|
+
// use dubhe_framework::dubhe_framework;
|
|
6
|
+
|
|
7
|
+
const ENotImplemented: u64 = 0;
|
|
8
|
+
|
|
9
|
+
#[test]
|
|
10
|
+
fun test_dubhe_framework() {
|
|
11
|
+
// pass
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[test, expected_failure(abort_code = ::dubhe_framework::dubhe_framework_tests::ENotImplemented)]
|
|
15
|
+
fun test_dubhe_framework_fail() {
|
|
16
|
+
abort ENotImplemented
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
*/
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dubhe-contract-template",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Simple starter template",
|
|
5
|
+
"author": "team@0xobelisk.com",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"// Utility Commands": "----------------",
|
|
9
|
+
"schema:gen": "pnpm dubhe schemagen --configPath ./dubhe.config.ts",
|
|
10
|
+
"account:gen": "NODE_NO_WARNINGS=1 ts-node scripts/generateAccount.ts",
|
|
11
|
+
"start": "pnpm dubhe localnode start",
|
|
12
|
+
"faucet": "pnpm dubhe faucet --network",
|
|
13
|
+
"check-balance": "NODE_NO_WARNINGS=1 ts-node scripts/checkBalance.ts",
|
|
14
|
+
"deploy:localnet": "NODE_NO_WARNINGS=1 ts-node scripts/deployment/localnet/deploy.ts",
|
|
15
|
+
"deploy:testnet": "NODE_NO_WARNINGS=1 ts-node scripts/deployment/testnet/deploy.ts"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@0xobelisk/sui-cli": "^0.5.25",
|
|
19
|
+
"@0xobelisk/sui-client": "^0.5.28",
|
|
20
|
+
"@0xobelisk/sui-common": "^0.5.21",
|
|
21
|
+
"dotenv": "^16.4.5",
|
|
22
|
+
"chalk": "^4.1.2"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"ts-node": "^10.9.1",
|
|
26
|
+
"typescript": "5.1.6"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Dubhe, NetworkType } from '@0xobelisk/sui-client';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
dotenv.config();
|
|
5
|
+
|
|
6
|
+
async function checkBalance(network: string) {
|
|
7
|
+
try {
|
|
8
|
+
if (!process.env.PRIVATE_KEY) {
|
|
9
|
+
console.error(chalk.red('Please set the PRIVATE_KEY environment variable'));
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!network) {
|
|
14
|
+
console.error(chalk.red('Network parameter is missing'));
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const dubhe = new Dubhe({
|
|
19
|
+
secretKey: process.env.PRIVATE_KEY,
|
|
20
|
+
networkType: network as NetworkType,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const balance = await dubhe.getBalance();
|
|
24
|
+
|
|
25
|
+
if (balance.totalBalance === '0') {
|
|
26
|
+
console.log(chalk.yellow(`Account balance is 0, need to get ${network} coins`));
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(
|
|
31
|
+
chalk.green(`Current account balance: ${(Number(balance.totalBalance) / 1_000_000_000).toFixed(4)} SUI`),
|
|
32
|
+
);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(chalk.red('Failed to check balance:', error));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
checkBalance(process.argv[2] as NetworkType);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { dubheConfig } from '../../dubhe.config';
|
|
4
|
+
import * as fsAsync from 'fs/promises';
|
|
5
|
+
import { DeploymentJsonType } from './types';
|
|
6
|
+
|
|
7
|
+
export async function deployContract(
|
|
8
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
9
|
+
dappsObjectId?: string,
|
|
10
|
+
): Promise<void> {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
console.log(chalk.blue(`\n📦 Deploying ${dubheConfig.name} contract...`));
|
|
13
|
+
|
|
14
|
+
let args = ['dubhe', 'publish', '--network', network, '--configPath', './dubhe.config.ts'];
|
|
15
|
+
if (dappsObjectId) {
|
|
16
|
+
args.push('--dappsObjectId', dappsObjectId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const childProcess = spawn('pnpm', args, {
|
|
20
|
+
shell: true,
|
|
21
|
+
stdio: 'inherit',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
childProcess.on('exit', code => {
|
|
25
|
+
if (code === 0) {
|
|
26
|
+
console.log(chalk.green(` ✅ ${dubheConfig.name} contract deployed successfully`));
|
|
27
|
+
} else {
|
|
28
|
+
console.error(chalk.red(` ❌ Deployment failed. Exit code: ${code}`));
|
|
29
|
+
reject(new Error(`Deployment failed. Exit code: ${code}`));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getContractDeploymentJson(projectPath: string, network: string): Promise<DeploymentJsonType> {
|
|
36
|
+
try {
|
|
37
|
+
const data = await fsAsync.readFile(
|
|
38
|
+
`${projectPath}/contracts/${dubheConfig.name}/.history/sui_${network}/latest.json`,
|
|
39
|
+
'utf8',
|
|
40
|
+
);
|
|
41
|
+
return JSON.parse(data) as DeploymentJsonType;
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error('Failed to read deployment history file');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { deployFramework } from '../../framework/deploy';
|
|
3
|
+
import { validateAndUpdatePackageId } from '../../framework/parse-history';
|
|
4
|
+
import { deployContract } from '../common';
|
|
5
|
+
|
|
6
|
+
async function delay(ms: number) {
|
|
7
|
+
await new Promise(resolve => setTimeout(resolve, ms));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
try {
|
|
12
|
+
// 1. Deploy framework contract
|
|
13
|
+
console.log(chalk.blue('\n🏗️ Deploying framework contract...'));
|
|
14
|
+
await deployFramework();
|
|
15
|
+
console.log(chalk.green(' ✅ Framework contract deployed successfully'));
|
|
16
|
+
await delay(1000);
|
|
17
|
+
|
|
18
|
+
// 2. Parse framework information
|
|
19
|
+
console.log(chalk.blue('\n🔍 Parsing framework information...'));
|
|
20
|
+
const deploymentData = await validateAndUpdatePackageId();
|
|
21
|
+
console.log(chalk.green(' ✅ Framework information parsed successfully'));
|
|
22
|
+
await delay(1000);
|
|
23
|
+
|
|
24
|
+
// 3. Deploy contract
|
|
25
|
+
const dappsObjectId = deploymentData.dappsObjectId;
|
|
26
|
+
await deployContract('localnet', dappsObjectId);
|
|
27
|
+
console.log(chalk.green('\n✅ All operations completed successfully'));
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error(chalk.red(`\n❌ Execution failed: ${error}`));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Use IIFE (Immediately Invoked Function Expression) to ensure async code executes correctly
|
|
35
|
+
(async () => {
|
|
36
|
+
try {
|
|
37
|
+
await main();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(chalk.red(`\n❌ Main program execution failed: ${error}`));
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { deployContract } from '../common';
|
|
3
|
+
import { dubheConfig } from '../../../dubhe.config';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
const TESTNET_FRAMEWORK_ID = '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
8
|
+
|
|
9
|
+
async function updateDubheMoveToml(projectName: string) {
|
|
10
|
+
try {
|
|
11
|
+
console.log(chalk.blue(`\n🔍 Updating Move.toml...`));
|
|
12
|
+
const moveTomlPath = path.join(process.cwd(), `contracts/${projectName}/Move.toml`);
|
|
13
|
+
let content = await fs.readFile(moveTomlPath, 'utf8');
|
|
14
|
+
|
|
15
|
+
content = content.replace(
|
|
16
|
+
/Dubhe = \{[^}]+\}/,
|
|
17
|
+
`Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "release-dubhe-v1.0.0-rc1" }`,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
content = content.replace(/^dubhe\s+=\s+"0x[0-9a-fA-F]+"/m, `dubhe = "${TESTNET_FRAMEWORK_ID}"`);
|
|
21
|
+
|
|
22
|
+
await fs.writeFile(moveTomlPath, content);
|
|
23
|
+
console.log(chalk.green(' ✅ Move.toml updated successfully'));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new Error(`Failed to update Move.toml: ${error}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function main() {
|
|
30
|
+
try {
|
|
31
|
+
await updateDubheMoveToml(dubheConfig.name);
|
|
32
|
+
await deployContract('testnet');
|
|
33
|
+
console.log(chalk.green('\n✅ All operations completed successfully'));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(chalk.red(`\n❌ Execution failed: ${error}`));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Use IIFE (Immediately Invoked Function Expression) to ensure async code executes correctly
|
|
41
|
+
(async () => {
|
|
42
|
+
try {
|
|
43
|
+
await main();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(chalk.red(`\n❌ Main program execution failed: ${error}`));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type schema = {
|
|
2
|
+
name: string;
|
|
3
|
+
objectId: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type DeploymentJsonType = {
|
|
7
|
+
projectName: string;
|
|
8
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
9
|
+
packageId: string;
|
|
10
|
+
schemas: schema[];
|
|
11
|
+
upgradeCap: string;
|
|
12
|
+
version: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as fsAsync from 'fs/promises';
|
|
2
|
+
import { FrameworkDeploymentJsonType } from './types';
|
|
3
|
+
|
|
4
|
+
export async function getFrameworkDeploymentJson(
|
|
5
|
+
projectPath: string,
|
|
6
|
+
network: string,
|
|
7
|
+
): Promise<FrameworkDeploymentJsonType> {
|
|
8
|
+
try {
|
|
9
|
+
const data = await fsAsync.readFile(
|
|
10
|
+
`${projectPath}/localnet/dubhe-framework/.history/sui_${network}/latest.json`,
|
|
11
|
+
'utf8',
|
|
12
|
+
);
|
|
13
|
+
return JSON.parse(data) as FrameworkDeploymentJsonType;
|
|
14
|
+
} catch {
|
|
15
|
+
throw new Error('Failed to read deployment history file');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Dubhe, loadMetadata, Transaction } from '@0xobelisk/sui-client';
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
import * as fsAsync from 'fs/promises';
|
|
4
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import { FrameworkDeploymentJsonType } from './types';
|
|
8
|
+
import { getFrameworkDeploymentJson } from './common';
|
|
9
|
+
import dotenv from 'dotenv';
|
|
10
|
+
dotenv.config();
|
|
11
|
+
|
|
12
|
+
export async function writeOutput(output: string, fullOutputPath: string, logPrefix?: string): Promise<void> {
|
|
13
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
14
|
+
|
|
15
|
+
writeFileSync(fullOutputPath, output);
|
|
16
|
+
if (logPrefix !== undefined) {
|
|
17
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function saveContractData(
|
|
22
|
+
projectName: string,
|
|
23
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
24
|
+
packageId: string,
|
|
25
|
+
upgradeCap: string,
|
|
26
|
+
dappsObjectId: string,
|
|
27
|
+
version: number,
|
|
28
|
+
) {
|
|
29
|
+
const DeploymentData: FrameworkDeploymentJsonType = {
|
|
30
|
+
projectName,
|
|
31
|
+
network,
|
|
32
|
+
packageId,
|
|
33
|
+
upgradeCap,
|
|
34
|
+
dappsObjectId,
|
|
35
|
+
version,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const path = process.cwd();
|
|
39
|
+
const storeDeploymentData = JSON.stringify(DeploymentData, null, 2);
|
|
40
|
+
writeOutput(
|
|
41
|
+
storeDeploymentData,
|
|
42
|
+
`${path}/localnet/dubhe-framework/.history/sui_${network}/latest.json`,
|
|
43
|
+
'Updated deployment log',
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function updateFrameworkMoveToml(frameworkPath: string, packageId: string | null = null) {
|
|
48
|
+
const moveTomlPath = `${frameworkPath}/Move.toml`;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
let content = await fsAsync.readFile(moveTomlPath, 'utf8');
|
|
52
|
+
|
|
53
|
+
if (packageId === null) {
|
|
54
|
+
// Pre-deployment: Reset addresses to 0x0
|
|
55
|
+
content = content.replace(/^published-at = "0x[0-9a-fA-F]+"/m, 'published-at = "0x0"');
|
|
56
|
+
content = content.replace(/^dubhe = "0x[0-9a-fA-F]+"/m, 'dubhe = "0x0"');
|
|
57
|
+
console.log(chalk.blue('Reset dubhe-framework addresses in Move.toml to 0x0'));
|
|
58
|
+
} else {
|
|
59
|
+
// Post-deployment: Update to new packageId
|
|
60
|
+
content = content.replace(/^published-at = "0x[0-9a-fA-F]+"/m, `published-at = "${packageId}"`);
|
|
61
|
+
content = content.replace(/^dubhe = "0x[0-9a-fA-F]+"/m, `dubhe = "${packageId}"`);
|
|
62
|
+
console.log(chalk.blue(`Updated dubhe-framework addresses in Move.toml to ${packageId}`));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await fsAsync.writeFile(moveTomlPath, content);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(chalk.red(`Failed to update Move.toml: ${error}`));
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function deployFramework() {
|
|
73
|
+
const network = 'localnet';
|
|
74
|
+
const path = process.cwd();
|
|
75
|
+
const name = 'dubhe_framework';
|
|
76
|
+
const frameworkPath = `${path}/localnet/dubhe-framework`;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
// Try to get historical deployment information
|
|
80
|
+
const deploymentData = await getFrameworkDeploymentJson(path, network);
|
|
81
|
+
|
|
82
|
+
// Check if the contract exists
|
|
83
|
+
try {
|
|
84
|
+
const metadata = await loadMetadata(network, deploymentData.packageId);
|
|
85
|
+
if (metadata) {
|
|
86
|
+
console.log(chalk.yellow('Framework contract already deployed on local network'));
|
|
87
|
+
return; // Contract already exists, return directly
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.log(
|
|
91
|
+
chalk.yellow('Previous deployment found but contract not accessible, proceeding with new deployment'),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.log(chalk.yellow('No previous deployment found, proceeding with new deployment'));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Reset Move.toml addresses before compilation
|
|
99
|
+
await updateFrameworkMoveToml(frameworkPath);
|
|
100
|
+
|
|
101
|
+
// Check for private key in environment variables
|
|
102
|
+
const privateKey = process.env.PRIVATE_KEY;
|
|
103
|
+
if (!privateKey) {
|
|
104
|
+
throw new Error('Missing PRIVATE_KEY environment variable');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Initialize Dubhe client
|
|
108
|
+
const dubhe = new Dubhe({
|
|
109
|
+
networkType: network,
|
|
110
|
+
secretKey: privateKey,
|
|
111
|
+
});
|
|
112
|
+
const keypair = dubhe.getKeypair();
|
|
113
|
+
|
|
114
|
+
const balance = await dubhe.getBalance();
|
|
115
|
+
console.log(chalk.blue(`Deployer Balance: ${(Number(balance.totalBalance) / 1_000_000_000).toFixed(4)} SUI`));
|
|
116
|
+
|
|
117
|
+
if (BigInt(balance.totalBalance) < BigInt(1000000000)) {
|
|
118
|
+
console.log(chalk.yellow('Balance is less than 1 SUI, requesting from faucet...'));
|
|
119
|
+
await dubhe.requestFaucet();
|
|
120
|
+
console.log(chalk.green('Successfully received SUI from faucet'));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Compile and get bytecode
|
|
124
|
+
let modules, dependencies;
|
|
125
|
+
try {
|
|
126
|
+
const buildResult = JSON.parse(
|
|
127
|
+
execSync(`sui move build --dump-bytecode-as-base64 --path ${frameworkPath}`, {
|
|
128
|
+
encoding: 'utf-8',
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
modules = buildResult.modules;
|
|
132
|
+
dependencies = buildResult.dependencies;
|
|
133
|
+
} catch (error: any) {
|
|
134
|
+
console.error(chalk.red('Error executing sui move build:'));
|
|
135
|
+
console.error(error.stdout);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
console.log(chalk.blue(`Deployer Address: ${keypair.toSuiAddress()}`));
|
|
140
|
+
|
|
141
|
+
// Create publish transaction
|
|
142
|
+
const tx = new Transaction();
|
|
143
|
+
const [upgradeCap] = tx.publish({
|
|
144
|
+
modules,
|
|
145
|
+
dependencies,
|
|
146
|
+
});
|
|
147
|
+
tx.transferObjects([upgradeCap], keypair.toSuiAddress());
|
|
148
|
+
|
|
149
|
+
// Execute transaction
|
|
150
|
+
try {
|
|
151
|
+
const result = await dubhe.signAndSendTxn(tx);
|
|
152
|
+
|
|
153
|
+
if (result.effects?.status.status === 'failure') {
|
|
154
|
+
console.log(chalk.red(`Failed to execute publish`));
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let packageId = '';
|
|
159
|
+
let upgradeCapId = '';
|
|
160
|
+
let dappsObjectId = '';
|
|
161
|
+
|
|
162
|
+
// Output deployment information
|
|
163
|
+
result.objectChanges!.map(object => {
|
|
164
|
+
if (object.type === 'published') {
|
|
165
|
+
console.log(chalk.blue(`Framework PackageId: ${object.packageId}`));
|
|
166
|
+
packageId = object.packageId;
|
|
167
|
+
}
|
|
168
|
+
if (object.type === 'created' && object.objectType === '0x2::package::UpgradeCap') {
|
|
169
|
+
console.log(chalk.blue(`Framework UpgradeCap: ${object.objectId}`));
|
|
170
|
+
upgradeCapId = object.objectId;
|
|
171
|
+
}
|
|
172
|
+
if (object.type === 'created' && object.objectType.includes('dapps_schema::Dapps')) {
|
|
173
|
+
console.log(chalk.blue(`Framework Dapps ObjectId: ${object.objectId}`));
|
|
174
|
+
dappsObjectId = object.objectId;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Update Move.toml addresses with new packageId
|
|
179
|
+
await updateFrameworkMoveToml(frameworkPath, packageId);
|
|
180
|
+
|
|
181
|
+
console.log(chalk.green(`Publish transaction digest: ${result.digest}`));
|
|
182
|
+
|
|
183
|
+
// Save contract data
|
|
184
|
+
saveContractData(
|
|
185
|
+
name,
|
|
186
|
+
network,
|
|
187
|
+
packageId,
|
|
188
|
+
upgradeCapId,
|
|
189
|
+
dappsObjectId,
|
|
190
|
+
1, // Initial version is 1
|
|
191
|
+
);
|
|
192
|
+
} catch (error: any) {
|
|
193
|
+
console.error(chalk.red(`Failed to execute publish`));
|
|
194
|
+
console.error(error.message);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// deployFramework();
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { loadMetadata } from '@0xobelisk/sui-client';
|
|
2
|
+
import { dubheConfig } from '../../dubhe.config';
|
|
3
|
+
import * as fsAsync from 'fs/promises';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { FrameworkDeploymentJsonType } from './types';
|
|
7
|
+
import { getFrameworkDeploymentJson } from './common';
|
|
8
|
+
|
|
9
|
+
async function updateMoveToml(packageName: string, dubhePackageId: string) {
|
|
10
|
+
const moveTomlPath = path.join(process.cwd(), 'contracts', packageName, 'Move.toml');
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
let content = await fsAsync.readFile(moveTomlPath, 'utf8');
|
|
14
|
+
|
|
15
|
+
// Update Dubhe dependency
|
|
16
|
+
content = content.replace(/Dubhe = \{[^}]+\}/, `Dubhe = { local = "../../localnet/dubhe-framework" }`);
|
|
17
|
+
|
|
18
|
+
// Update regex to match possible multiple spaces
|
|
19
|
+
content = content.replace(/^dubhe\s+=\s+"0x[0-9a-fA-F]+"/m, `dubhe = "${dubhePackageId}"`);
|
|
20
|
+
|
|
21
|
+
await fsAsync.writeFile(moveTomlPath, content);
|
|
22
|
+
console.log(chalk.green(`Successfully updated ${moveTomlPath}`));
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error(chalk.red(`Failed to update Move.toml: ${error}`));
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function validateAndUpdatePackageId(): Promise<FrameworkDeploymentJsonType> {
|
|
30
|
+
const network = 'localnet';
|
|
31
|
+
const projectPath = process.cwd();
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const packageName = dubheConfig.name;
|
|
35
|
+
|
|
36
|
+
if (!packageName) {
|
|
37
|
+
throw new Error('Package name not found in the config file');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Get historical deployment information
|
|
41
|
+
const deploymentData = await getFrameworkDeploymentJson(projectPath, network);
|
|
42
|
+
|
|
43
|
+
// Verify if packageId exists on chain
|
|
44
|
+
try {
|
|
45
|
+
const metadata = await loadMetadata(network, deploymentData.packageId);
|
|
46
|
+
if (!metadata) {
|
|
47
|
+
throw new Error('PackageId does not exist on chain');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log(chalk.green(`Verification successful: PackageId ${deploymentData.packageId} exists on chain`));
|
|
51
|
+
|
|
52
|
+
// Update Move.toml file
|
|
53
|
+
await updateMoveToml(packageName, deploymentData.packageId);
|
|
54
|
+
|
|
55
|
+
console.log(chalk.green('All updates completed successfully'));
|
|
56
|
+
return deploymentData;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(chalk.red(`Verification failed: ${error}`));
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(chalk.red(`Processing failed: ${error}`));
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Export main function
|
|
68
|
+
export async function parseAndUpdateFramework() {
|
|
69
|
+
try {
|
|
70
|
+
const packageId = await validateAndUpdatePackageId();
|
|
71
|
+
return packageId;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(chalk.red(`Framework update failed: ${error}`));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Dubhe } from '@0xobelisk/sui-client';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
|
|
4
|
+
async function generateAccount() {
|
|
5
|
+
const path = process.cwd();
|
|
6
|
+
|
|
7
|
+
// Check if .env file exists and has content
|
|
8
|
+
let privateKey: string;
|
|
9
|
+
try {
|
|
10
|
+
const envContent = fs.readFileSync(`${path}/.env`, 'utf8');
|
|
11
|
+
const match = envContent.match(/PRIVATE_KEY=(.+)/);
|
|
12
|
+
if (match && match[1]) {
|
|
13
|
+
privateKey = match[1];
|
|
14
|
+
const dubhe = new Dubhe({ secretKey: privateKey });
|
|
15
|
+
const keypair = dubhe.getKeypair();
|
|
16
|
+
|
|
17
|
+
console.log(`Using existing Account: ${keypair.toSuiAddress()}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// .env file doesn't exist or failed to read, continue to generate new account
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// If no existing private key, generate new account
|
|
25
|
+
const dubhe = new Dubhe();
|
|
26
|
+
const keypair = dubhe.getKeypair();
|
|
27
|
+
privateKey = keypair.getSecretKey();
|
|
28
|
+
|
|
29
|
+
const chainFolderPath = `${path}/src/chain`;
|
|
30
|
+
fs.mkdirSync(chainFolderPath, { recursive: true });
|
|
31
|
+
|
|
32
|
+
fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
|
|
33
|
+
|
|
34
|
+
console.log(`Generate new Account: ${keypair.toSuiAddress()}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
generateAccount();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ts-node": {
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "CommonJS"
|
|
5
|
+
}
|
|
6
|
+
},
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"target": "es6",
|
|
9
|
+
"lib": [
|
|
10
|
+
"dom",
|
|
11
|
+
"dom.iterable",
|
|
12
|
+
"esnext"
|
|
13
|
+
],
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"strict": false,
|
|
17
|
+
"forceConsistentCasingInFileNames": true,
|
|
18
|
+
"noEmit": true,
|
|
19
|
+
"esModuleInterop": true,
|
|
20
|
+
"module": "esnext",
|
|
21
|
+
"moduleResolution": "node",
|
|
22
|
+
"resolveJsonModule": true,
|
|
23
|
+
"isolatedModules": true,
|
|
24
|
+
"jsx": "preserve",
|
|
25
|
+
"incremental": true
|
|
26
|
+
},
|
|
27
|
+
"include": [
|
|
28
|
+
"next-env.d.ts",
|
|
29
|
+
"**/*.ts",
|
|
30
|
+
"**/*.tsx"
|
|
31
|
+
],
|
|
32
|
+
"exclude": [
|
|
33
|
+
"node_modules"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -5,9 +5,9 @@ edition = "2024.beta"
|
|
|
5
5
|
|
|
6
6
|
[dependencies]
|
|
7
7
|
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.36.2" }
|
|
8
|
-
Dubhe = { git = "https://github.com/0xobelisk/dubhe.git",
|
|
8
|
+
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "release-dubhe-v1.0.0-rc1" }
|
|
9
9
|
|
|
10
10
|
[addresses]
|
|
11
11
|
sui = "0x2"
|
|
12
|
-
dubhe = "
|
|
13
|
-
counter = "0x0"
|
|
12
|
+
dubhe = "0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6"
|
|
13
|
+
counter = "0x0"
|