@0xobelisk/sui-cli 0.5.8 → 0.5.9
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/obelisk.js +7 -7
- package/dist/obelisk.js.map +1 -1
- package/package.json +2 -1
- package/src/commands/faucet.ts +58 -58
- package/src/utils/publishHandler.ts +183 -175
- package/src/utils/upgradeHandler.ts +238 -227
- package/src/utils/utils.ts +1 -1
|
@@ -1,184 +1,192 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Obelisk } from '@0xobelisk/sui-client';
|
|
2
|
+
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
8
|
-
import { execSync } from
|
|
9
|
-
import chalk from
|
|
10
|
-
import { ObeliskCliError } from
|
|
4
|
+
getFullnodeUrl,
|
|
5
|
+
SuiClient,
|
|
6
|
+
SuiTransactionBlockResponse,
|
|
7
|
+
} from '@mysten/sui.js/client';
|
|
8
|
+
import { execSync } from 'child_process';
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import { ObeliskCliError } from './errors';
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from
|
|
12
|
+
updateVersionInFile,
|
|
13
|
+
saveContractData,
|
|
14
|
+
validatePrivateKey,
|
|
15
|
+
} from './utils';
|
|
16
16
|
|
|
17
17
|
export async function publishHandler(
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
name: string,
|
|
19
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
20
20
|
) {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const path = process.cwd();
|
|
22
|
+
const projectPath = `${path}/contracts/${name}`;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const privateKey = process.env.PRIVATE_KEY;
|
|
25
|
+
if (!privateKey)
|
|
26
|
+
throw new ObeliskCliError(
|
|
27
|
+
`Missing PRIVATE_KEY environment variable.
|
|
28
28
|
Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
|
|
29
29
|
in your contracts directory to use the default sui private key.`
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const privateKeyFormat = validatePrivateKey(privateKey);
|
|
33
|
+
if (privateKeyFormat === false) {
|
|
34
|
+
throw new ObeliskCliError(`Please check your privateKey.`);
|
|
35
|
+
}
|
|
36
|
+
const obelisk = new Obelisk({
|
|
37
|
+
secretKey: privateKeyFormat,
|
|
38
|
+
});
|
|
39
|
+
const keypair = obelisk.getKeypair();
|
|
40
|
+
|
|
41
|
+
const client = new SuiClient({
|
|
42
|
+
url: getFullnodeUrl(network),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Set version 1
|
|
46
|
+
await updateVersionInFile(projectPath, '1');
|
|
47
|
+
let modules: any, dependencies: any;
|
|
48
|
+
try {
|
|
49
|
+
const {
|
|
50
|
+
modules: extractedModules,
|
|
51
|
+
dependencies: extractedDependencies,
|
|
52
|
+
} = JSON.parse(
|
|
53
|
+
execSync(
|
|
54
|
+
`sui move build --dump-bytecode-as-base64 --path ${projectPath}`,
|
|
55
|
+
{
|
|
56
|
+
encoding: 'utf-8',
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
modules = extractedModules;
|
|
61
|
+
dependencies = extractedDependencies;
|
|
62
|
+
} catch (error: any) {
|
|
63
|
+
console.error(chalk.red('Error executing sui move build:'));
|
|
64
|
+
console.error(error.stdout);
|
|
65
|
+
process.exit(1); // You might want to exit with a non-zero status code to indicate an error
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log(chalk.blue(`Account: ${keypair.toSuiAddress()}`));
|
|
69
|
+
|
|
70
|
+
const tx = new TransactionBlock();
|
|
71
|
+
const [upgradeCap] = tx.publish({
|
|
72
|
+
modules,
|
|
73
|
+
dependencies,
|
|
74
|
+
});
|
|
75
|
+
tx.transferObjects(
|
|
76
|
+
[upgradeCap],
|
|
77
|
+
tx.pure(keypair.getPublicKey().toSuiAddress())
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
let result: SuiTransactionBlockResponse;
|
|
81
|
+
try {
|
|
82
|
+
result = await client.signAndExecuteTransactionBlock({
|
|
83
|
+
signer: keypair,
|
|
84
|
+
transactionBlock: tx,
|
|
85
|
+
options: {
|
|
86
|
+
showObjectChanges: true,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
} catch (error: any) {
|
|
90
|
+
console.error(chalk.red(`Failed to execute publish, please republish`));
|
|
91
|
+
console.error(error.message);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (result.effects?.status.status === 'failure') {
|
|
96
|
+
console.log(chalk.red(`Failed to execute publish, please republish`));
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let version = 1;
|
|
101
|
+
let packageId = '';
|
|
102
|
+
let worldId = '';
|
|
103
|
+
let upgradeCapId = '';
|
|
104
|
+
let adminCapId = '';
|
|
105
|
+
result.objectChanges!.map(object => {
|
|
106
|
+
if (object.type === 'published') {
|
|
107
|
+
console.log(chalk.blue(`${name} PackageId: ${object.packageId}`));
|
|
108
|
+
packageId = object.packageId;
|
|
109
|
+
}
|
|
110
|
+
if (
|
|
111
|
+
object.type === 'created' &&
|
|
112
|
+
object.objectType.endsWith('::world::World')
|
|
113
|
+
) {
|
|
114
|
+
console.log(chalk.blue(`${name} WorldId: ${object.objectId}`));
|
|
115
|
+
worldId = object.objectId;
|
|
116
|
+
}
|
|
117
|
+
if (
|
|
118
|
+
object.type === 'created' &&
|
|
119
|
+
object.objectType === '0x2::package::UpgradeCap'
|
|
120
|
+
) {
|
|
121
|
+
console.log(chalk.blue(`${name} UpgradeCap: ${object.objectId}`));
|
|
122
|
+
upgradeCapId = object.objectId;
|
|
123
|
+
}
|
|
124
|
+
if (
|
|
125
|
+
object.type === 'created' &&
|
|
126
|
+
object.objectType.endsWith('::world::AdminCap')
|
|
127
|
+
) {
|
|
128
|
+
console.log(chalk.blue(`${name} AdminCapId: ${object.objectId}`));
|
|
129
|
+
adminCapId = object.objectId;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
console.log(chalk.green(`Publish transaction digest: ${result.digest}`));
|
|
134
|
+
|
|
135
|
+
saveContractData(
|
|
136
|
+
name,
|
|
137
|
+
network,
|
|
138
|
+
packageId,
|
|
139
|
+
worldId,
|
|
140
|
+
upgradeCapId,
|
|
141
|
+
adminCapId,
|
|
142
|
+
version
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
console.log('Executing the deployHook: ');
|
|
146
|
+
const delay = (ms: number) =>
|
|
147
|
+
new Promise(resolve => setTimeout(resolve, ms));
|
|
148
|
+
await delay(5000);
|
|
149
|
+
|
|
150
|
+
const deployHookTx = new TransactionBlock();
|
|
151
|
+
|
|
152
|
+
deployHookTx.moveCall({
|
|
153
|
+
target: `${packageId}::deploy_hook::run`,
|
|
154
|
+
arguments: [
|
|
155
|
+
deployHookTx.object(worldId),
|
|
156
|
+
deployHookTx.object(adminCapId),
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
let deployHookResult: SuiTransactionBlockResponse;
|
|
161
|
+
try {
|
|
162
|
+
deployHookResult = await client.signAndExecuteTransactionBlock({
|
|
163
|
+
signer: keypair,
|
|
164
|
+
transactionBlock: deployHookTx,
|
|
165
|
+
options: {
|
|
166
|
+
showEffects: true,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
} catch (error: any) {
|
|
170
|
+
console.error(
|
|
171
|
+
chalk.red(
|
|
172
|
+
`Failed to execute deployHook, please republish or manually call deploy_hook::run`
|
|
173
|
+
)
|
|
174
|
+
);
|
|
175
|
+
console.error(error.message);
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (deployHookResult.effects?.status.status === 'success') {
|
|
180
|
+
console.log(
|
|
181
|
+
chalk.green(
|
|
182
|
+
`Successful auto-execution of deployHook, please check the transaction digest: ${deployHookResult.digest}`
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
} else {
|
|
186
|
+
console.log(
|
|
187
|
+
chalk.yellow(
|
|
188
|
+
`Failed to execute deployHook, please republish or manually call deploy_hook::run`
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
184
192
|
}
|