@0xobelisk/sui-common 0.5.15 ā 0.5.18
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/LICENSE +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +75 -60
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/codegen/types/index.ts +1 -1
- package/src/codegen/utils/config.ts +6 -6
- package/src/codegen/utils/errors.ts +1 -1
- package/src/codegen/utils/index.ts +5 -5
- package/src/codegen/utils/renderMove/common.ts +27 -33
- package/src/codegen/utils/renderMove/generateDappKey.ts +23 -14
- package/src/codegen/utils/renderMove/generateSchema.ts +192 -117
- package/src/codegen/utils/renderMove/generateScript.ts +54 -42
- package/src/codegen/utils/renderMove/generateSystem.ts +25 -18
- package/src/codegen/utils/renderMove/generateToml.ts +16 -6
- package/src/codegen/utils/renderMove/schemaGen.ts +69 -0
- package/src/debug.ts +2 -2
- package/src/codegen/utils/renderMove/worldgen.ts +0 -34
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { formatAndWriteMove } from
|
|
3
|
-
import { existsSync } from
|
|
1
|
+
import { DubheConfig } from '../../types';
|
|
2
|
+
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
4
|
|
|
5
|
-
export async function generateDeployHook(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
export async function generateDeployHook(
|
|
6
|
+
config: DubheConfig,
|
|
7
|
+
srcPrefix: string
|
|
8
|
+
) {
|
|
9
|
+
console.log('\nš Starting Deploy Hook Generation...');
|
|
10
|
+
console.log(
|
|
11
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
if (
|
|
15
|
+
!existsSync(
|
|
16
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
|
|
17
|
+
)
|
|
18
|
+
) {
|
|
19
|
+
let code = `module ${config.name}::deploy_hook {
|
|
20
|
+
use dubhe::dapps_schema::Dapps;
|
|
21
|
+
use dubhe::dapps_system;
|
|
14
22
|
use ${config.name}::dapp_key::DappKey;
|
|
15
23
|
use std::ascii;
|
|
16
24
|
use sui::clock::Clock;
|
|
17
25
|
use sui::transfer::public_share_object;
|
|
18
26
|
#[test_only]
|
|
19
|
-
use
|
|
27
|
+
use dubhe::dapps_schema;
|
|
20
28
|
#[test_only]
|
|
21
29
|
use sui::clock;
|
|
22
30
|
#[test_only]
|
|
@@ -25,7 +33,7 @@ export async function generateDeployHook(config: ObeliskConfig, srcPrefix: strin
|
|
|
25
33
|
use sui::test_scenario::Scenario;
|
|
26
34
|
|
|
27
35
|
public entry fun run(dapps: &mut Dapps, clock: &Clock, ctx: &mut TxContext) {
|
|
28
|
-
// Register the dapp to
|
|
36
|
+
// Register the dapp to dubhe.
|
|
29
37
|
dapps_system::register<DappKey>(
|
|
30
38
|
dapps,
|
|
31
39
|
ascii::string(b"${config.name}"),
|
|
@@ -33,16 +41,20 @@ export async function generateDeployHook(config: ObeliskConfig, srcPrefix: strin
|
|
|
33
41
|
clock,
|
|
34
42
|
ctx
|
|
35
43
|
);
|
|
36
|
-
${Object.keys(config.schemas)
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
${Object.keys(config.schemas)
|
|
45
|
+
.map(schemaName => {
|
|
46
|
+
return `let ${schemaName} = ${config.name}::${schemaName}_schema::register(dapps, ctx);`;
|
|
47
|
+
})
|
|
48
|
+
.join('\n')}
|
|
39
49
|
// Logic that needs to be automated once the contract is deployed
|
|
40
50
|
|
|
41
51
|
|
|
42
52
|
// Share the dapp object with the public
|
|
43
|
-
${Object.keys(config.schemas)
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
${Object.keys(config.schemas)
|
|
54
|
+
.map(schemaName => {
|
|
55
|
+
return `public_share_object(${schemaName});`;
|
|
56
|
+
})
|
|
57
|
+
.join('\n')}
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
#[test_only]
|
|
@@ -63,22 +75,23 @@ export async function generateDeployHook(config: ObeliskConfig, srcPrefix: strin
|
|
|
63
75
|
}
|
|
64
76
|
}
|
|
65
77
|
`;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
await formatAndWriteMove(
|
|
79
|
+
code,
|
|
80
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,
|
|
81
|
+
'formatAndWriteMove'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
console.log('ā
Deploy Hook Generation Complete\n');
|
|
72
85
|
}
|
|
73
86
|
|
|
74
|
-
export function generateMigrate(config:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
use
|
|
87
|
+
export function generateMigrate(config: DubheConfig, srcPrefix: string) {
|
|
88
|
+
if (
|
|
89
|
+
!existsSync(
|
|
90
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`
|
|
91
|
+
)
|
|
92
|
+
) {
|
|
93
|
+
let code = `module ${config.name}::migrate {
|
|
94
|
+
use dubhe::world::{World, AdminCap};
|
|
82
95
|
|
|
83
96
|
/// Not the right admin for this world
|
|
84
97
|
const ENotAdmin: u64 = 0;
|
|
@@ -89,7 +102,7 @@ export function generateMigrate(config: ObeliskConfig, srcPrefix: string) {
|
|
|
89
102
|
public entry fun run(world: &mut World, admin_cap: &AdminCap) {
|
|
90
103
|
assert!(world.admin() == object::id(admin_cap), ENotAdmin);
|
|
91
104
|
assert!(world.version() < VERSION, ENotUpgrade);
|
|
92
|
-
*
|
|
105
|
+
*dubhe::world::mut_version(world, admin_cap) = VERSION;
|
|
93
106
|
}
|
|
94
107
|
|
|
95
108
|
public fun assert_version(world: &World){
|
|
@@ -97,11 +110,10 @@ export function generateMigrate(config: ObeliskConfig, srcPrefix: string) {
|
|
|
97
110
|
}
|
|
98
111
|
}
|
|
99
112
|
`;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
113
|
+
formatAndWriteMove(
|
|
114
|
+
code,
|
|
115
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,
|
|
116
|
+
'formatAndWriteMove'
|
|
117
|
+
);
|
|
118
|
+
}
|
|
106
119
|
}
|
|
107
|
-
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { formatAndWriteMove } from
|
|
3
|
-
import { existsSync } from
|
|
1
|
+
import { DubheConfig } from '../../types';
|
|
2
|
+
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
4
|
|
|
5
|
-
export async function generateSystem(config:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
export async function generateSystem(config: DubheConfig, srcPrefix: string) {
|
|
6
|
+
console.log('\nāļø Starting System Generation...');
|
|
7
|
+
config.systems.map(async systemName => {
|
|
8
|
+
console.log(` āā Generating system: ${systemName}`);
|
|
9
|
+
console.log(
|
|
10
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
if (
|
|
14
|
+
!existsSync(
|
|
15
|
+
`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
|
|
16
|
+
)
|
|
17
|
+
) {
|
|
18
|
+
let code = `module ${config.name}::${systemName}_system {
|
|
13
19
|
|
|
14
20
|
}
|
|
15
21
|
`;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
await formatAndWriteMove(
|
|
23
|
+
code,
|
|
24
|
+
`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,
|
|
25
|
+
'formatAndWriteMove'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
console.log('ā
System Generation Complete\n');
|
|
23
30
|
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DubheConfig } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
|
|
4
|
-
export async function generateToml(
|
|
4
|
+
export async function generateToml(
|
|
5
|
+
config: DubheConfig,
|
|
6
|
+
srcPrefix: string,
|
|
7
|
+
frameworkId: string
|
|
8
|
+
) {
|
|
9
|
+
console.log('\nš Starting Move.toml Generation...');
|
|
10
|
+
console.log(
|
|
11
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`
|
|
12
|
+
);
|
|
13
|
+
|
|
5
14
|
let code = `[package]
|
|
6
15
|
name = "${config.name}"
|
|
7
16
|
version = "0.0.1"
|
|
8
17
|
edition = "2024.beta"
|
|
9
18
|
|
|
10
19
|
[dependencies]
|
|
11
|
-
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.
|
|
12
|
-
|
|
20
|
+
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.36.2" }
|
|
21
|
+
Dubhe = { git = "https://github.com/0xobelisk/dubhe.git", subdir = "packages/dubhe-framework", rev = "main" }
|
|
13
22
|
|
|
14
23
|
[addresses]
|
|
15
|
-
sui =
|
|
16
|
-
|
|
24
|
+
sui = "0x2"
|
|
25
|
+
dubhe = "${frameworkId}"
|
|
17
26
|
${config.name} = "0x0"
|
|
18
27
|
`;
|
|
19
28
|
await formatAndWriteMove(
|
|
@@ -21,4 +30,5 @@ ${config.name} = "0x0"
|
|
|
21
30
|
`${srcPrefix}/contracts/${config.name}/Move.toml`,
|
|
22
31
|
'formatAndWriteMove'
|
|
23
32
|
);
|
|
33
|
+
console.log('ā
Move.toml Generation Complete\n');
|
|
24
34
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SchemaType, DubheConfig } from '../../types';
|
|
2
|
+
import { rmdirSync, existsSync } from 'fs';
|
|
3
|
+
import { deleteFolderRecursive } from './common';
|
|
4
|
+
import { generateSystem } from './generateSystem';
|
|
5
|
+
import { generateToml } from './generateToml';
|
|
6
|
+
import { generateSchemaData, generateSchemaStructure } from './generateSchema';
|
|
7
|
+
import { generateDeployHook, generateMigrate } from './generateScript';
|
|
8
|
+
import { generateDappKey } from './generateDappKey';
|
|
9
|
+
|
|
10
|
+
function matchFrameworkId(
|
|
11
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
12
|
+
): string {
|
|
13
|
+
switch (network) {
|
|
14
|
+
case 'testnet':
|
|
15
|
+
return '0x1736475f476c5dec96f33c03c778843f572239d3a887d795eef66d2836484c28';
|
|
16
|
+
case 'localnet':
|
|
17
|
+
return '0x1736475f476c5dec96f33c03c778843f572239d3a887d795eef66d2836484c28';
|
|
18
|
+
default:
|
|
19
|
+
return '0x1736475f476c5dec96f33c03c778843f572239d3a887d795eef66d2836484c28';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function schemaGen(
|
|
24
|
+
config: DubheConfig,
|
|
25
|
+
srcPrefix?: string,
|
|
26
|
+
network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
27
|
+
frameworkId?: string
|
|
28
|
+
) {
|
|
29
|
+
console.log('\nš Starting Schema Generation Process...');
|
|
30
|
+
console.log('š Project Configuration:');
|
|
31
|
+
console.log(` āā Name: ${config.name}`);
|
|
32
|
+
console.log(
|
|
33
|
+
` āā Description: ${config.description || 'No description provided'}`
|
|
34
|
+
);
|
|
35
|
+
console.log(` āā Network: ${network || 'testnet'}`);
|
|
36
|
+
console.log(
|
|
37
|
+
` āā Framework ID: ${
|
|
38
|
+
frameworkId || matchFrameworkId(network ?? 'testnet')
|
|
39
|
+
}\n`
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const path = srcPrefix ?? process.cwd();
|
|
43
|
+
|
|
44
|
+
frameworkId = frameworkId || matchFrameworkId(network ?? 'testnet');
|
|
45
|
+
|
|
46
|
+
if (existsSync(`${path}/contracts/${config.name}`)) {
|
|
47
|
+
deleteFolderRecursive(
|
|
48
|
+
`${path}/contracts/${config.name}/sources/codegen`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
|
|
53
|
+
await generateToml(config, path, frameworkId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
!existsSync(
|
|
58
|
+
`${path}/contracts/${config.name}/sources/script/deploy_hook.move`
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
await generateDeployHook(config, path);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await generateSystem(config, path);
|
|
65
|
+
await generateSchemaData(config.name, config.schemas, path);
|
|
66
|
+
await generateSchemaStructure(config.name, config.schemas, path);
|
|
67
|
+
await generateDappKey(config, path);
|
|
68
|
+
console.log('ā
Schema Generation Process Complete!\n');
|
|
69
|
+
}
|
package/src/debug.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import createDebug from "debug";
|
|
2
2
|
|
|
3
|
-
export const debug = createDebug("
|
|
4
|
-
export const error = createDebug("
|
|
3
|
+
export const debug = createDebug("dubhe:common");
|
|
4
|
+
export const error = createDebug("dubhe:common");
|
|
5
5
|
|
|
6
6
|
// Pipe debug output to stdout instead of stderr
|
|
7
7
|
debug.log = console.debug.bind(console);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { SchemaType, ObeliskConfig } from "../../types";
|
|
2
|
-
import { rmdirSync, existsSync } from "fs";
|
|
3
|
-
import { deleteFolderRecursive } from "./common";
|
|
4
|
-
import { generateSystem } from "./generateSystem";
|
|
5
|
-
import { generateToml } from "./generateToml";
|
|
6
|
-
import {generateSchemaData, generateSchemaStructure} from "./generateSchema";
|
|
7
|
-
import {generateDeployHook, generateMigrate} from "./generateScript";
|
|
8
|
-
import {generateDappKey} from "./generateDappKey";
|
|
9
|
-
|
|
10
|
-
export async function worldgen(config: ObeliskConfig, srcPrefix?: string) {
|
|
11
|
-
let path = "";
|
|
12
|
-
if (srcPrefix === undefined) {
|
|
13
|
-
path = process.cwd();
|
|
14
|
-
} else {
|
|
15
|
-
path = srcPrefix;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (existsSync(`${path}/contracts/${config.name}`)) {
|
|
19
|
-
deleteFolderRecursive(`${path}/contracts/${config.name}/sources/codegen`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
|
|
23
|
-
await generateToml(config, path);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!existsSync(`${path}/contracts/${config.name}/sources/script/deploy_hook.move`)) {
|
|
27
|
-
await generateDeployHook(config, path);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
await generateSystem(config, path);
|
|
31
|
-
await generateSchemaData(config.name, config.schemas, path);
|
|
32
|
-
await generateSchemaStructure(config.name, config.schemas, path);
|
|
33
|
-
await generateDappKey(config, path);
|
|
34
|
-
}
|