@0xobelisk/sui-cli 0.5.28 → 0.5.30

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/README.md CHANGED
@@ -5,7 +5,7 @@ The Dubhe CLI is used for building and developing a Dubhe project.
5
5
  It comes with
6
6
 
7
7
 
8
- 1. `schemagen <configPath>`: Autogenerate Dubhe schemas based on the store schemas config file
8
+ 1. `schemagen`: Autogenerate Dubhe schemas based on the store schemas config file
9
9
  2. `publish`: Deploy your own project on the specified sui network.
10
10
  3. `upgrade`: Upgrade your own project on the specified sui network.
11
11
  4. `localnode`: Start a local Sui node for development
@@ -31,7 +31,7 @@ Generates Store libraries from a `dubhe.config.ts` file. See the [Store Config a
31
31
 
32
32
  ```bash
33
33
  # in a folder with a dubhe.config.ts
34
- dubhe schemagen dubhe.config.ts
34
+ dubhe schemagen --config-path dubhe.config.ts
35
35
  ```
36
36
 
37
37
  ### `publish`
package/dist/dubhe.js CHANGED
@@ -1,51 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import ko from"yargs";import{hideBin as So}from"yargs/helpers";import{Dubhe as Ue}from"@0xobelisk/sui-client";import{Transaction as W}from"@mysten/sui/transactions";import{getFullnodeUrl as Le,SuiClient as Ke}from"@mysten/sui/client";import{execSync as je}from"child_process";import $ from"chalk";import R from"chalk";import{ZodError as Se}from"zod";import{fromZodError as Ie,ValidationError as $e}from"zod-validation-error";var J=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"},w=class extends Error{name="DubheCliError"},T=class extends Error{name="UpgradeError"},V=class extends Error{name="FsIibError"};function D(e){if(e instanceof $e)console.log(R.redBright(e.message));else if(e instanceof Se){let o=Ie(e,{prefixSeparator:`
3
- - `,issueSeparator:`
4
- - `});console.log(R.redBright(o.message))}else e instanceof J?(console.log(R.red(e.message)),console.log(""),console.log(R.blue("To learn more about Dubhe's configuration, please go to https://github.com/0xobelisk"))):e instanceof w?console.log(R.red(e)):console.log(e)}import*as Z from"fs/promises";import{mkdirSync as Me,writeFileSync as Fe}from"fs";import{dirname as Re}from"path";import{SUI_PRIVATE_KEY_PREFIX as Oe}from"@mysten/sui/cryptography";import{execSync as Ee,spawn as Pe}from"child_process";import y from"chalk";function De(){try{let e=process.platform==="win32"?'tasklist /FI "IMAGENAME eq sui.exe" /FO CSV /NH':'pgrep -f "sui start"',o=Ee(e).toString().trim();return process.platform==="win32"?o.toLowerCase().includes("sui.exe"):o.length>0}catch{return!1}}async function U(e=!1){if(console.log(`
5
- \u{1F50D} Checking Local Node Status...`),console.log(" \u251C\u2500 Scanning running processes"),De()){console.log(y.yellow(`
6
- \u26A0\uFE0F Warning: Local Node Already Running`)),console.log(y.yellow(" \u251C\u2500 Cannot start a new instance")),console.log(y.yellow(" \u2514\u2500 Please stop the existing process first"));return}console.log(`
7
- \u{1F680} Starting Local Node...`),console.log(" \u251C\u2500 Mode: "+(e?"Background":"Foreground")),console.log(" \u251C\u2500 Faucet: Enabled"),console.log(" \u2514\u2500 Force Regenesis: Yes");try{let o=Pe("sui",["start","--with-faucet","--force-regenesis"],{env:{...process.env,RUST_LOG:"off,sui_node=info"},stdio:e?"ignore":"inherit",detached:e});o.on("error",t=>{console.error(y.red(`
8
- \u274C Failed to Start Local Node`)),console.error(y.red(` \u2514\u2500 Error: ${t.message}`))}),e?(o.unref(),console.log(y.green(`
9
- \u2705 Local Node Started in Background`)),process.platform==="win32"?(console.log(`
10
- \u{1F4A1} Helpful Commands:`),console.log(" \u251C\u2500 Check Process: tasklist | findstr sui.exe"),console.log(" \u2514\u2500 Stop Node: taskkill /PID <process_id> /F")):(console.log(`
11
- \u{1F4A1} Helpful Commands:`),console.log(" \u251C\u2500 Check Process: pgrep -f 'sui start'"),console.log(" \u2514\u2500 Stop Node: kill <process_id>"))):(o.on("exit",t=>{t===0?(console.log(y.green(`
12
- \u2705 Local Node Stopped`)),console.log(y.green(" \u2514\u2500 Exit Status: Normal"))):(console.error(y.red(`
13
- \u274C Local Node Crashed`)),console.error(y.red(` \u2514\u2500 Exit Code: ${t}`)))}),console.log(y.cyan(`
14
- \u{1F4E1} Local Node Running`)),console.log(y.cyan(" \u2514\u2500 Press Ctrl+C to stop")),await new Promise(()=>{}))}catch(o){console.error(y.red(`
15
- \u274C Failed to Start Local Node`)),console.error(y.red(` \u2514\u2500 Error: ${o.message}`))}}import{execSync as Ne}from"child_process";import k from"chalk";async function q(){console.log(`
16
- \u{1F50D} Checking Local Node Status...`);try{let e=process.platform==="win32"?'tasklist /FI "IMAGENAME eq sui.exe" /FO CSV /NH':"ps aux | grep '[s]ui start --with-faucet --force-regenesis'",o=Ne(e,{encoding:"utf8"});(process.platform==="win32"?o.toLowerCase().includes("sui.exe"):o.split(`
17
- `).filter(Boolean).length>0)?(console.log(k.green(`
18
- \u2705 Node Status: Running`)),console.log(k.gray(`
19
- \u{1F4CA} Process Details:`)),console.log(k.gray(` \u2514\u2500 ${o.trim()}`))):(console.log(k.red(`
20
- \u274C Node Status: Not Running`)),console.log(k.yellow(`
21
- \u{1F4A1} Quick Start:`)),console.log(k.yellow(" \u2514\u2500 Run `dubhe localnode start`")))}catch{console.log(k.red(`
22
- \u274C Node Status: Not Running`)),console.log(k.yellow(`
23
- \u{1F4A1} Quick Start:`)),console.log(k.yellow(" \u2514\u2500 Run `dubhe localnode start`"))}}import{execSync as Q}from"child_process";async function L(){console.log("Stopping local node...");try{let e=process.platform==="win32"?'tasklist /FI "IMAGENAME eq sui.exe" /FO CSV /NH':"ps aux | grep '[s]ui start --with-faucet --force-regenesis'",o=Q(e,{encoding:"utf8"});if(!o){console.log("No running local node process found");return}let t;if(process.platform==="win32"){let s=o.match(/"sui\.exe",["']?(\d+)/i);t=s?s[1]:null}else t=o.toString().split(/\s+/)[1];if(!t){console.log("No running local node process found");return}process.platform==="win32"?Q(`taskkill /PID ${t} /F`):process.kill(Number(t)),console.log("\u2705 Local node stopped successfully")}catch(e){e.code==="ESRCH"||e.message.includes("no running tasks")?console.log("No running local node process found"):console.error("\u274C Error stopping local node:",e.message)}}import*as K from"fs";import S from"chalk";import{spawn as Ae}from"child_process";function N(e){if(e.startsWith(Oe))return e.length===70?e:!1;if(e.startsWith("0x")){let o=e.slice(2);return o.length===64?o:!1}else return e.length===64?e:!1}async function O(e,o){try{let t=await Z.readFile(`${e}/.history/sui_${o}/latest.json`,"utf8");return JSON.parse(t)}catch{throw new V("Fs read deployment file failed.")}}async function X(e,o){return(await O(e,o)).schemas}async function ee(e,o){return(await O(e,o)).version}async function oe(e,o){return(await O(e,o)).packageId}async function te(e,o){return(await O(e,o)).upgradeCap}async function j(e,o){return(await O(e,o)).schemaHub}function A(e,o,t,s,n,u,c){let d={projectName:e,network:o,packageId:t,schemas:c,upgradeCap:s,schemaHub:n,version:u},l=process.cwd(),r=JSON.stringify(d,null,2);Te(r,`${l}/contracts/${e}/.history/sui_${o}/latest.json`,"Update deploy log")}async function Te(e,o,t){Me(Re(o),{recursive:!0}),Fe(o,e),t!==void 0&&console.log(`${t}: ${o}`)}function Ve(e){switch(e){case"localnet":return'Dubhe = { local = "../dubhe-framework" }';case"testnet":return'Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.0.0" }';case"mainnet":return'Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-mainnet-v1.0.0" }';default:throw new Error(`Unsupported network: ${e}`)}}function ne(e,o){let t=K.readFileSync(e,"utf-8"),s=Ve(o),n=t.replace(/Dubhe = \{.*\}/,s);K.writeFileSync(e,n,"utf-8"),console.log(`Updated Dubhe dependency in ${e} for ${o}.`)}async function H(e){try{return new Promise((o,t)=>{let s=Ae("sui",["client","switch","--env",e],{env:{...process.env},stdio:"pipe"});s.stdout.on("data",n=>{console.log(S.green(`${n.toString()}`))}),s.stderr.on("data",n=>{console.error(S.red(`
24
- \u274C Failed to Switch Env`)),console.error(S.red(` Error: ${n.toString()}`))}),s.on("error",n=>{console.error(S.red(`
25
- \u274C Failed to Switch Env`)),console.error(S.red(` Error: ${n.message}`)),t(n)}),s.on("exit",n=>{n!==0?(console.error(S.red(`
26
- \u274C Process exited with code: ${n}`)),t(new Error(`Process exited with code: ${n}`))):(console.log(S.green(`
27
- \u2705 Environment switched successfully.`)),o())})})}catch(o){console.error(S.red(`
28
- \u274C Failed to Switch Env`)),console.error(S.red(` \u2514\u2500 Error: ${o}`))}}var se=e=>new Promise(o=>setTimeout(o,e));import*as E from"fs";import*as re from"path";async function He(e){switch(e){case"localnet":{let o=process.cwd();return await j(`${o}/contracts/dubhe-framework`,e)}case"testnet":return"0x8dbf8d28ac027ba214c9e0951b09f6842843be6cb87242b7d9a326a2677cd47a";default:return"0x8dbf8d28ac027ba214c9e0951b09f6842843be6cb87242b7d9a326a2677cd47a"}}function ae(e,o){if(!E.existsSync(e))return;let t=E.readFileSync(e,"utf-8"),s=new RegExp(`\\[env\\.${o}\\][\\s\\S]*?(?=\\[|$)`,"g"),n=t.replace(s,"");E.writeFileSync(e,n,"utf-8")}function ie(e,o,t,s,n){let u=re.resolve(e),c=E.readFileSync(u,"utf-8"),d=c.split(`
29
- `),l=d.findIndex(h=>h.trim()===`[env.${o}]`),r={chainId:s,originalPublishedId:"",latestPublishedId:"",publishedVersion:0};if(l===-1)if(t==="publish")r.originalPublishedId=n,r.latestPublishedId=n,r.publishedVersion=1;else throw new Error(`Network type [env.${o}] not found in the file and cannot upgrade.`);else{for(let h=l+1;h<d.length;h++){let b=d[h].trim();if(b.startsWith("["))break;let[C,_]=b.split("=").map(v=>v.trim().replace(/"/g,""));switch(C){case"original-published-id":r.originalPublishedId=_;break;case"latest-published-id":r.latestPublishedId=_;break;case"published-version":r.publishedVersion=parseInt(_,10);break}}t==="publish"?(r.originalPublishedId=n,r.latestPublishedId=n,r.publishedVersion=1):t==="upgrade"&&(r.latestPublishedId=n,r.publishedVersion+=1)}let p=`
30
- [env.${o}]
31
- chain-id = "${r.chainId}"
32
- original-published-id = "${r.originalPublishedId}"
33
- latest-published-id = "${r.latestPublishedId}"
34
- published-version = "${r.publishedVersion}"
35
- `,f=l===-1?c+p:d.slice(0,l).join(`
36
- `)+p;E.writeFileSync(u,f,"utf-8")}function Be(e){return e.split("_").map((o,t)=>o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()).join("")}function Ye(e){let o=e.split("::");return o.length>0?o[o.length-1]:""}function ce(e){let o,t;try{let s=JSON.parse(je(`sui move build --dump-bytecode-as-base64 --path ${e}`,{encoding:"utf-8"}));o=s.modules,t=s.dependencies,console.log(" \u2514\u2500 Build successful")}catch(s){console.error($.red(" \u2514\u2500 Build failed")),console.error(s.stdout),process.exit(1)}return[o,t]}async function Ge(e,o,t,s,n){let u=await He(s);console.log("dappsObjectId",u);let c=await e.getChainIdentifier();ae(`${n}/Move.lock`,s),console.log(`
37
- \u{1F680} Starting Contract Publication...`),console.log(` \u251C\u2500 Project: ${n}`),console.log(` \u251C\u2500 Network: ${s}`),console.log(` \u251C\u2500 ChainId: ${c}`),console.log(" \u251C\u2500 Validating Environment...");let d=o.getKeypair();console.log(` \u2514\u2500 Account: ${d.toSuiAddress()}`),console.log(`
38
- \u{1F4E6} Building Contract...`);let[l,r]=ce(n);console.log(`
39
- \u{1F504} Publishing Contract...`);let p=new W,[f]=p.publish({modules:l,dependencies:r});p.transferObjects([f],d.toSuiAddress());let h;try{h=await e.signAndExecuteTransaction({signer:d,transaction:p,options:{showObjectChanges:!0}})}catch(i){console.error($.red(" \u2514\u2500 Publication failed")),console.error(i.message),process.exit(1)}h.effects?.status.status==="failure"&&(console.log($.red(" \u2514\u2500 Publication failed")),process.exit(1)),console.log(" \u251C\u2500 Processing publication results...");let b=1,C="",_=[],v="",a="";h.objectChanges.map(i=>{i.type==="published"&&(console.log(` \u251C\u2500 Package ID: ${i.packageId}`),C=i.packageId),i.type==="created"&&i.objectType==="0x2::package::UpgradeCap"&&(console.log(` \u251C\u2500 Upgrade Cap: ${i.objectId}`),v=i.objectId),i.type==="created"&&i.objectType.includes("schema_hub")&&(console.log(` \u251C\u2500 Schema Hub: ${i.objectId}`),a=i.objectId)}),console.log(` \u2514\u2500 Transaction: ${h.digest}`),ie(`${n}/Move.lock`,s,"publish",c,C),console.log(`
40
- \u26A1 Executing Deploy Hook...`),await se(5e3);let g=new W;g.setGasBudget(2e9);let[I]=g.splitCoins(g.gas,["1000000000"]);g.moveCall({target:`${C}::deploy_hook::run`,arguments:[g.object(a),g.object(u),g.object(v),g.object("0x6"),I]});let m;try{m=await e.signAndExecuteTransaction({signer:d,transaction:g,options:{showEffects:!0,showObjectChanges:!0}})}catch(i){console.error($.red(" \u2514\u2500 Deploy hook execution failed")),console.error(i.message),process.exit(1)}m.effects?.status.status==="success"?(console.log(" \u251C\u2500 Hook execution successful"),console.log(` \u251C\u2500 Transaction: ${m.digest}`),console.log(`
41
- \u{1F4CB} Created Schemas:`),m.objectChanges?.map(i=>{if(i.type==="created"&&i.objectType.includes("_schema")&&!i.objectType.includes("dynamic_field")){console.log(` \u251C\u2500 ${i.objectType}`),console.log(` \u2514\u2500 ID: ${i.objectId}`);let x={};for(let F in t.schemas)Be(F)===Ye(i.objectType)&&(x=t.schemas[F].structure);_.push({name:i.objectType,objectId:i.objectId,structure:x})}}),A(t.name,s,C,v,a,b,_),console.log(`
42
- \u2705 Contract Publication Complete
43
- `)):(console.log($.yellow(" \u2514\u2500 Deploy hook execution failed")),console.log($.yellow(" Please republish or manually call deploy_hook::run")))}async function Je(e,o,t){let n=`${process.cwd()}/contracts/dubhe-framework`,u=await e.getChainIdentifier();console.log(` \u2514\u2500 Chain ID: ${u}`),ae(`${n}/Move.lock`,t),console.log(`
44
- \u{1F680} Starting Contract Publication...`),console.log(` \u251C\u2500 Project: ${n}`),console.log(` \u251C\u2500 Network: ${t}`),console.log(` \u251C\u2500 ChainId: ${u}`),console.log(" \u251C\u2500 Validating Environment...");let c=o.getKeypair();console.log(` \u2514\u2500 Account: ${c.toSuiAddress()}`),console.log(`
45
- \u{1F4E6} Building Contract...`);let[d,l]=ce(n);console.log(`
46
- \u{1F504} Publishing Contract...`);let r=new W,[p]=r.publish({modules:d,dependencies:l});r.transferObjects([p],c.toSuiAddress());let f;try{f=await e.signAndExecuteTransaction({signer:c,transaction:r,options:{showObjectChanges:!0}})}catch(a){console.error($.red(" \u2514\u2500 Publication failed")),console.error(a.message),process.exit(1)}f.effects?.status.status==="failure"&&(console.log($.red(" \u2514\u2500 Publication failed")),process.exit(1)),console.log(" \u251C\u2500 Processing publication results...");let h=1,b="",C=[],_="",v="";f.objectChanges.map(a=>{a.type==="published"&&(console.log(` \u251C\u2500 Package ID: ${a.packageId}`),b=a.packageId),a.type==="created"&&a.objectType==="0x2::package::UpgradeCap"&&(console.log(` \u251C\u2500 Upgrade Cap: ${a.objectId}`),_=a.objectId),a.type==="created"&&a.objectType.includes("dapps")&&(console.log(` \u251C\u2500 Dapps: ${a.objectId}`),v=a.objectId)}),console.log(` \u2514\u2500 Transaction: ${f.digest}`),ie(`${n}/Move.lock`,t,"publish",u,b),A("dubhe-framework",t,b,_,v,h,C)}async function le(e,o,t){await H(o);let s=process.env.PRIVATE_KEY;if(!s)throw new w(`Missing PRIVATE_KEY environment variable.
47
- Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
48
- in your contracts directory to use the default sui private key.`);let n=N(s);if(n===!1)throw new w("Please check your privateKey.");let u=new Ue({secretKey:n}),c=new Ke({url:Le(o)});if(t=="dubhe-framework")await Je(c,u,o);else{let l=`${process.cwd()}/contracts/${e.name}`;ne(`${l}/Move.toml`,o),await Ge(c,u,e,o,l)}}import qe from"chalk";function de(){console.log(qe.yellow(`
2
+ import Et from"yargs";import{hideBin as St}from"yargs/helpers";import{execSync as ze,spawn as ie}from"child_process";import w from"chalk";import ke from"chalk";function N(){console.log(ke.yellow(`
49
3
  Welcome to Dubhe
50
4
  --from team@obelisk
51
5
  ________ ___ ___ ________ ___ ___ _______
@@ -56,21 +10,51 @@ Welcome to Dubhe
56
10
  \\ \\_______\\ \\_______\\ \\_______\\ \\__\\ \\__\\ \\_______\\
57
11
  \\|_______|\\|_______|\\|_______|\\|__|\\|__|\\|_______|
58
12
 
59
- `))}var We={command:"localnode <action>",describe:"Manage local Sui node",builder(e){return e.positional("action",{describe:"Action to perform",choices:["start","stop","status","restart"],type:"string",demandOption:!0}).option("background",{alias:"b",type:"boolean",description:"Run node in background",default:!1})},async handler(e){let{action:o,background:t}=e;try{switch(o){case"start":await U(t);break;case"stop":await L();break;case"status":await q();break;case"restart":await ze(t);break}}catch(s){console.error("Error executing command:",s),process.exit(1)}}};async function ze(e){console.log("Restarting local Sui node..."),await L(),await U(e),console.log("Local node has been restarted")}var ue=We;import{Dubhe as Qe}from"@0xobelisk/sui-client";import{requestSuiFromFaucetV0 as Ze,getFaucetHost as Xe}from"@mysten/sui/faucet";import{SuiClient as eo,getFullnodeUrl as oo}from"@mysten/sui/client";var to={command:"faucet",describe:"Interact with a Dubhe faucet",builder(e){return e.options({network:{type:"string",desc:"URL of the Dubhe faucet",choices:["testnet","devnet","localnet"],default:"localnet"},recipient:{type:"string",desc:"Sui address to fund"}})},async handler({network:e,recipient:o}){let t="";if(o===void 0){let c=process.env.PRIVATE_KEY;if(!c)throw new w(`Missing PRIVATE_KEY environment variable.
13
+ `))}import{Dubhe as Re}from"@0xobelisk/sui-client";import{Transaction as G}from"@mysten/sui/transactions";import{getFullnodeUrl as Te,SuiClient as Ne}from"@mysten/sui/client";import{execSync as Ue}from"child_process";import E from"chalk";import j from"chalk";import{ZodError as Ie}from"zod";import{fromZodError as Ee,ValidationError as Se}from"zod-validation-error";var Y=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"},y=class extends Error{name="DubheCliError"},U=class extends Error{name="UpgradeError"},K=class extends Error{name="FsIibError"};function D(e){if(e instanceof Se)console.log(j.redBright(e.message));else if(e instanceof Ie){let t=Ee(e,{prefixSeparator:`
14
+ - `,issueSeparator:`
15
+ - `});console.log(j.redBright(t.message))}else e instanceof Y?(console.log(j.red(e.message)),console.log(""),console.log(j.blue("To learn more about Dubhe's configuration, please go to https://github.com/0xobelisk"))):e instanceof y?console.log(j.red(e)):console.log(e)}import*as Z from"fs/promises";import{mkdirSync as Pe,writeFileSync as De}from"fs";import{dirname as Me}from"path";import{SUI_PRIVATE_KEY_PREFIX as Fe}from"@mysten/sui/cryptography";import*as V from"fs";import k from"chalk";import{spawn as Oe}from"child_process";function I(e){if(e.startsWith(Fe))return e.length===70?e:!1;if(e.startsWith("0x")){let t=e.slice(2);return t.length===64?t:!1}else return e.length===64?e:!1}async function A(e,t){try{let o=await Z.readFile(`${e}/.history/sui_${t}/latest.json`,"utf8");return JSON.parse(o)}catch{throw new K("Fs read deployment file failed.")}}async function X(e,t){return(await A(e,t)).schemas}async function Q(e,t){return(await A(e,t)).version}async function ee(e,t){return(await A(e,t)).packageId}async function te(e,t){return(await A(e,t)).upgradeCap}async function q(e,t){return(await A(e,t)).schemaHub}function R(e,t,o,s,n,c,a){let p={projectName:e,network:t,packageId:o,schemas:a,upgradeCap:s,schemaHub:n,version:c},d=process.cwd(),r=JSON.stringify(p,null,2);je(r,`${d}/contracts/${e}/.history/sui_${t}/latest.json`,"Update deploy log")}async function je(e,t,o){Pe(Me(t),{recursive:!0}),De(t,e),o!==void 0&&console.log(`${o}: ${t}`)}function Ae(e){switch(e){case"localnet":return'Dubhe = { local = "../dubhe-framework" }';case"testnet":return'Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.0.0" }';case"mainnet":return'Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-mainnet-v1.0.0" }';default:throw new Error(`Unsupported network: ${e}`)}}function L(e,t){let o=V.readFileSync(e,"utf-8"),s=Ae(t),n=o.replace(/Dubhe = \{.*\}/,s);V.writeFileSync(e,n,"utf-8"),console.log(`Updated Dubhe dependency in ${e} for ${t}.`)}async function M(e){try{return new Promise((t,o)=>{let s=Oe("sui",["client","switch","--env",e],{env:{...process.env},stdio:"pipe"});s.stdout.on("data",n=>{console.log(k.green(`${n.toString()}`))}),s.stderr.on("data",n=>{console.error(k.red(`
16
+ \u274C Failed to Switch Env`)),console.error(k.red(` Error: ${n.toString()}`))}),s.on("error",n=>{console.error(k.red(`
17
+ \u274C Failed to Switch Env`)),console.error(k.red(` Error: ${n.message}`)),o(n)}),s.on("exit",n=>{n!==0?(console.error(k.red(`
18
+ \u274C Process exited with code: ${n}`)),o(new Error(`Process exited with code: ${n}`))):t()})})}catch(t){console.error(k.red(`
19
+ \u274C Failed to Switch Env`)),console.error(k.red(` \u2514\u2500 Error: ${t}`))}}var T=e=>new Promise(t=>setTimeout(t,e));import*as S from"fs";import*as oe from"path";async function Ke(e){switch(e){case"localnet":{let t=process.cwd();return await q(`${t}/contracts/dubhe-framework`,e)}case"testnet":return"0x8dbf8d28ac027ba214c9e0951b09f6842843be6cb87242b7d9a326a2677cd47a";default:return"0x8dbf8d28ac027ba214c9e0951b09f6842843be6cb87242b7d9a326a2677cd47a"}}function ne(e,t){if(!S.existsSync(e))return;let o=S.readFileSync(e,"utf-8"),s=new RegExp(`\\[env\\.${t}\\][\\s\\S]*?(?=\\[|$)`,"g"),n=o.replace(s,"");S.writeFileSync(e,n,"utf-8")}function se(e,t,o,s,n){let c=oe.resolve(e),a=S.readFileSync(c,"utf-8"),p=a.split(`
20
+ `),d=p.findIndex(h=>h.trim()===`[env.${t}]`),r={chainId:s,originalPublishedId:"",latestPublishedId:"",publishedVersion:0};if(d===-1)if(o==="publish")r.originalPublishedId=n,r.latestPublishedId=n,r.publishedVersion=1;else throw new Error(`Network type [env.${t}] not found in the file and cannot upgrade.`);else{for(let h=d+1;h<p.length;h++){let b=p[h].trim();if(b.startsWith("["))break;let[x,v]=b.split("=").map(_=>_.trim().replace(/"/g,""));switch(x){case"original-published-id":r.originalPublishedId=v;break;case"latest-published-id":r.latestPublishedId=v;break;case"published-version":r.publishedVersion=parseInt(v,10);break}}o==="publish"?(r.originalPublishedId=n,r.latestPublishedId=n,r.publishedVersion=1):o==="upgrade"&&(r.latestPublishedId=n,r.publishedVersion+=1)}let u=`
21
+ [env.${t}]
22
+ chain-id = "${r.chainId}"
23
+ original-published-id = "${r.originalPublishedId}"
24
+ latest-published-id = "${r.latestPublishedId}"
25
+ published-version = "${r.publishedVersion}"
26
+ `,f=d===-1?a+u:p.slice(0,d).join(`
27
+ `)+u;S.writeFileSync(c,f,"utf-8")}function Ve(e){return e.split("_").map((t,o)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function qe(e){let t=e.split("::");return t.length>0?t[t.length-1]:""}function re(e){let t,o;try{let s=JSON.parse(Ue(`sui move build --dump-bytecode-as-base64 --path ${e}`,{encoding:"utf-8",stdio:"pipe"}));t=s.modules,o=s.dependencies,console.log(" \u2514\u2500 Build successful")}catch(s){console.error(E.red(" \u2514\u2500 Build failed")),console.error(s.stdout),process.exit(1)}return[t,o]}async function Le(e,t,o,s,n){let c=await Ke(s);console.log("dappsObjectId",c);let a=await e.getChainIdentifier();ne(`${n}/Move.lock`,s),console.log(`
28
+ \u{1F680} Starting Contract Publication...`),console.log(` \u251C\u2500 Project: ${n}`),console.log(` \u251C\u2500 Network: ${s}`),console.log(` \u251C\u2500 ChainId: ${a}`),console.log(" \u251C\u2500 Validating Environment...");let p=t.getKeypair();console.log(` \u2514\u2500 Account: ${p.toSuiAddress()}`),console.log(`
29
+ \u{1F4E6} Building Contract...`);let[d,r]=re(n);console.log(`
30
+ \u{1F504} Publishing Contract...`);let u=new G,[f]=u.publish({modules:d,dependencies:r});u.transferObjects([f],p.toSuiAddress());let h;try{h=await e.signAndExecuteTransaction({signer:p,transaction:u,options:{showObjectChanges:!0}})}catch(l){console.error(E.red(" \u2514\u2500 Publication failed")),console.error(l.message),process.exit(1)}h.effects?.status.status==="failure"&&(console.log(E.red(" \u2514\u2500 Publication failed")),process.exit(1)),console.log(" \u251C\u2500 Processing publication results...");let b=1,x="",v=[],_="",i="";h.objectChanges.map(l=>{l.type==="published"&&(console.log(` \u251C\u2500 Package ID: ${l.packageId}`),x=l.packageId),l.type==="created"&&l.objectType==="0x2::package::UpgradeCap"&&(console.log(` \u251C\u2500 Upgrade Cap: ${l.objectId}`),_=l.objectId),l.type==="created"&&l.objectType.includes("schema_hub")&&(console.log(` \u251C\u2500 Schema Hub: ${l.objectId}`),i=l.objectId)}),console.log(` \u2514\u2500 Transaction: ${h.digest}`),se(`${n}/Move.lock`,s,"publish",a,x),console.log(`
31
+ \u26A1 Executing Deploy Hook...`),await T(5e3);let g=new G;g.setGasBudget(2e9);let[$]=g.splitCoins(g.gas,["1000000000"]);g.moveCall({target:`${x}::deploy_hook::run`,arguments:[g.object(i),g.object(c),g.object(_),g.object("0x6"),$]});let m;try{m=await e.signAndExecuteTransaction({signer:p,transaction:g,options:{showEffects:!0,showObjectChanges:!0}})}catch(l){console.error(E.red(" \u2514\u2500 Deploy hook execution failed")),console.error(l.message),process.exit(1)}m.effects?.status.status==="success"?(console.log(" \u251C\u2500 Hook execution successful"),console.log(` \u251C\u2500 Transaction: ${m.digest}`),console.log(`
32
+ \u{1F4CB} Created Schemas:`),m.objectChanges?.map(l=>{if(l.type==="created"&&l.objectType.includes("_schema")&&!l.objectType.includes("dynamic_field")){console.log(` \u251C\u2500 ${l.objectType}`),console.log(` \u2514\u2500 ID: ${l.objectId}`);let C={};for(let O in o.schemas)Ve(O)===qe(l.objectType)&&(C=o.schemas[O].structure);v.push({name:l.objectType,objectId:l.objectId,structure:C})}}),R(o.name,s,x,_,i,b,v),console.log(`
33
+ \u2705 Contract Publication Complete
34
+ `)):(console.log(E.yellow(" \u2514\u2500 Deploy hook execution failed")),console.log(E.yellow(" Please republish or manually call deploy_hook::run")))}async function W(e,t,o){let n=`${process.cwd()}/contracts/dubhe-framework`,c=await e.getChainIdentifier();console.log(` \u2514\u2500 Chain ID: ${c}`),ne(`${n}/Move.lock`,o),console.log(`
35
+ \u{1F680} Starting Contract Publication...`),console.log(` \u251C\u2500 Project: ${n}`),console.log(` \u251C\u2500 Network: ${o}`),console.log(` \u251C\u2500 ChainId: ${c}`),console.log(" \u251C\u2500 Validating Environment...");let a=t.getKeypair();console.log(` \u2514\u2500 Account: ${a.toSuiAddress()}`),console.log(`
36
+ \u{1F4E6} Building Contract...`);let[p,d]=re(n);console.log(`
37
+ \u{1F504} Publishing Contract...`);let r=new G,[u]=r.publish({modules:p,dependencies:d});r.transferObjects([u],a.toSuiAddress());let f;try{f=await e.signAndExecuteTransaction({signer:a,transaction:r,options:{showObjectChanges:!0}})}catch(i){console.error(E.red(" \u2514\u2500 Publication failed")),console.error(i.message),process.exit(1)}f.effects?.status.status==="failure"&&(console.log(E.red(" \u2514\u2500 Publication failed")),process.exit(1)),console.log(" \u251C\u2500 Processing publication results...");let h=1,b="",x=[],v="",_="";f.objectChanges.map(i=>{i.type==="published"&&(console.log(` \u251C\u2500 Package ID: ${i.packageId}`),b=i.packageId),i.type==="created"&&i.objectType==="0x2::package::UpgradeCap"&&(console.log(` \u251C\u2500 Upgrade Cap: ${i.objectId}`),v=i.objectId),i.type==="created"&&i.objectType.includes("dapps")&&(console.log(` \u251C\u2500 Dapps: ${i.objectId}`),_=i.objectId)}),console.log(` \u2514\u2500 Transaction: ${f.digest}`),se(`${n}/Move.lock`,o,"publish",c,b),R("dubhe-framework",o,b,v,_,h,x)}async function ae(e,t,o){await M(t);let s=process.env.PRIVATE_KEY;if(!s)throw new y(`Missing PRIVATE_KEY environment variable.
38
+ Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
39
+ in your contracts directory to use the default sui private key.`);let n=I(s);if(n===!1)throw new y("Please check your privateKey.");let c=new Re({secretKey:n}),a=new Ne({url:Te(t)});if(o=="dubhe-framework")await W(a,c,t);else{let d=`${process.cwd()}/contracts/${e.name}`;L(`${d}/Move.toml`,t),await Le(a,c,e,t,d)}}import{Dubhe as ce}from"@0xobelisk/sui-client";import{getFullnodeUrl as Be,SuiClient as He}from"@mysten/sui/client";function Ye(){try{let e=process.platform==="win32"?'tasklist /FI "IMAGENAME eq sui.exe" /FO CSV /NH':'pgrep -f "sui start"',t=ze(e).toString().trim();return process.platform==="win32"?t.toLowerCase().includes("sui.exe"):t.length>0}catch{return!1}}async function Ge(){let e=["suiprivkey1qq3ez3dje66l8pypgxynr7yymwps6uhn7vyczespj84974j3zya0wdpu76v","suiprivkey1qp6vcyg8r2x88fllmjmxtpzjl95gd9dugqrgz7xxf50w6rqdqzetg7x4d7s","suiprivkey1qpy3a696eh3m55fwa8h38ss063459u4n2dm9t24w2hlxxzjp2x34q8sdsnc","suiprivkey1qzxwp29favhzrjd95f6uj9nskjwal6nh9g509jpun395y6g72d6jqlmps4c","suiprivkey1qzhq4lv38sesah4uzsqkkmeyjx860xqjdz8qgw36tmrdd5tnle3evxpng57","suiprivkey1qzez45sjjsepjgtksqvpq6jw7dzw3zq0dx7a4sulfypd73acaynw5jl9x2c"];console.log("\u{1F4DD}Accounts"),console.log("=========="),e.forEach((t,o)=>{let n=new ce({secretKey:t}).getKeypair();ie("curl",["--location","--request","POST","http://127.0.0.1:9123/gas","--header","Content-Type: application/json","--data-raw",`{"FixedAmountRequest": {"recipient": "${n.toSuiAddress()}"}}`],{env:{...process.env},stdio:"ignore",detached:!0}),console.log(` \u250C\u2500 Account #${o}: ${n.toSuiAddress()}(1000 SUI)`),console.log(` \u2514\u2500 Private Key: ${t}`)}),console.log("=========="),console.log(w.yellow("\u26A0\uFE0FWARNING: These accounts, and their private keys, are publicly known.")),console.log(w.yellow("Any funds sent to them on Mainnet or any other live network WILL BE LOST."))}async function le(){if(Ye()){console.log(w.yellow(`
40
+ \u26A0\uFE0F Warning: Local Node Already Running`)),console.log(w.yellow(" \u251C\u2500 Cannot start a new instance")),console.log(w.yellow(" \u2514\u2500 Please stop the existing process first"));return}N(),console.log("\u{1F680} Starting Local Node...");try{let e=ie("sui",["start","--with-faucet","--force-regenesis"],{env:{...process.env,RUST_LOG:"off,sui_node=info"},stdio:"ignore",detached:!0});e.on("error",c=>{console.error(w.red(`
41
+ \u274C Failed to Start Local Node`)),console.error(w.red(` \u2514\u2500 Error: ${c.message}`))}),await T(5e3),console.log(" \u251C\u2500 Faucet: Enabled"),console.log(" \u2514\u2500 Force Regenesis: Yes"),console.log(" \u2514\u2500 HTTP server: http://127.0.0.1:9000/"),console.log(" \u2514\u2500 Faucet server: http://127.0.0.1:9123/"),await Ge(),await T(2e3);let t=I("suiprivkey1qzez45sjjsepjgtksqvpq6jw7dzw3zq0dx7a4sulfypd73acaynw5jl9x2c");if(t===!1)throw new y("Please check your privateKey.");let o=new ce({secretKey:t}),s=new He({url:Be("localnet")}),n=console.log;console.log=()=>{},await W(s,o,"localnet"),console.log=n,process.on("SIGINT",()=>{console.log(w.yellow(`
42
+ \u{1F514} Stopping Local Node...`)),e&&(e.kill(),console.log(w.green("\u2705 Local Node Stopped"))),process.exit()})}catch(e){console.error(w.red(`
43
+ \u274C Failed to Start Local Node`)),console.error(w.red(` \u2514\u2500 Error: ${e.message}`))}}var We={command:"node",describe:"Manage local Sui node",builder(e){return e},async handler(){try{await le()}catch(e){console.error("Error executing command:",e),process.exit(1)}}},de=We;import{Dubhe as Je}from"@0xobelisk/sui-client";import{requestSuiFromFaucetV0 as Ze,getFaucetHost as Xe}from"@mysten/sui/faucet";import{SuiClient as Qe,getFullnodeUrl as et}from"@mysten/sui/client";var tt={command:"faucet",describe:"Interact with a Dubhe faucet",builder(e){return e.options({network:{type:"string",desc:"URL of the Dubhe faucet",choices:["testnet","devnet","localnet"],default:"localnet"},recipient:{type:"string",desc:"Sui address to fund"}})},async handler({network:e,recipient:t}){let o="";if(t===void 0){let a=process.env.PRIVATE_KEY;if(!a)throw new y(`Missing PRIVATE_KEY environment variable.
60
44
  Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
61
- in your contracts directory to use the default sui private key.`);let d=N(c);if(d===!1)throw new w("Please check your PRIVATE_KEY.");t=new Qe({secretKey:d}).getKeypair().toSuiAddress()}else t=o;console.log(`
62
- \u{1F30A} Starting Faucet Operation...`),console.log(` \u251C\u2500 Network: ${e}`),o===void 0?(console.log(" \u251C\u2500 Using Environment PrivateKey"),console.log(` \u251C\u2500 Generated Address: ${t}`)):console.log(` \u251C\u2500 Using Provided Address: ${t}`),console.log(" \u251C\u2500 Requesting funds from faucet..."),await Ze({host:Xe(e),recipient:t}),console.log(" \u2514\u2500 Checking balance...");let s=new eo({url:oo(e)}),n={owner:t},u=await s.getBalance(n);console.log(`
63
- \u{1F4B0} Account Summary`),console.log(` \u251C\u2500 Address: ${t}`),console.log(` \u2514\u2500 Balance: ${(Number(u.totalBalance)/1e9).toFixed(4)} SUI`),console.log(`
45
+ in your contracts directory to use the default sui private key.`);let p=I(a);if(p===!1)throw new y("Please check your PRIVATE_KEY.");o=new Je({secretKey:p}).getKeypair().toSuiAddress()}else o=t;console.log(`
46
+ \u{1F30A} Starting Faucet Operation...`),console.log(` \u251C\u2500 Network: ${e}`),t===void 0?(console.log(" \u251C\u2500 Using Environment PrivateKey"),console.log(` \u251C\u2500 Generated Address: ${o}`)):console.log(` \u251C\u2500 Using Provided Address: ${o}`),console.log(" \u251C\u2500 Requesting funds from faucet..."),await Ze({host:Xe(e),recipient:o}),console.log(" \u2514\u2500 Checking balance...");let s=new Qe({url:et(e)}),n={owner:o},c=await s.getBalance(n);console.log(`
47
+ \u{1F4B0} Account Summary`),console.log(` \u251C\u2500 Address: ${o}`),console.log(` \u2514\u2500 Balance: ${(Number(c.totalBalance)/1e9).toFixed(4)} SUI`),console.log(`
64
48
  \u2705 Faucet Operation Complete
65
- `),process.exit(0)}},pe=to;import{schemaGen as no,loadConfig as so}from"@0xobelisk/sui-common";import ro from"chalk";var ao={command:"schemagen",describe:"Autogenerate Dubhe schemas based on the config file",builder:{configPath:{type:"string",default:"dubhe.config.ts",desc:"Path to the config file"},network:{type:"string",choices:["mainnet","testnet","devnet","localnet"],desc:"Node network (mainnet/testnet/devnet/localnet)"},frameworkId:{type:"string",desc:"Framework Package ID"}},async handler({configPath:e,network:o,frameworkId:t}){try{let s=await so(e);await no(s,void 0,o,t),process.exit(0)}catch(s){console.log(ro.red("Schemagen failed!")),console.error(s.message)}}},ge=ao;import{loadConfig as io}from"@0xobelisk/sui-common";var co={command:"publish",describe:"Publish dubhe move contract",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet"],desc:"Node network (mainnet/testnet/devnet/localnet)"},configPath:{type:"string",default:"dubhe.config.ts",desc:"Configuration file path"},contractName:{type:"string",desc:"Optional contract name"}})},async handler({network:e,configPath:o,contractName:t}){try{let s=await io(o);await le(s,e,t)}catch(s){D(s),process.exit(1)}process.exit(0)}},me=co;import{Dubhe as lo}from"@0xobelisk/sui-client";import{Transaction as uo,UpgradePolicy as po}from"@mysten/sui/transactions";import{getFullnodeUrl as go,SuiClient as mo}from"@mysten/sui/client";import{execSync as fo}from"child_process";import B from"chalk";import*as M from"fs";import*as fe from"path";function ho(e,o){o.forEach(t=>{let s=`${e}/sources/codegen/schemas/${t.schemaName}.move`,n=M.readFileSync(s,"utf-8"),u=new RegExp(`public fun migrate\\(_${t.schemaName}: &mut ${z(t.schemaName)}, _cap: &UpgradeCap\\) {[^}]*}`),c=`
66
- public fun migrate(${t.schemaName}: &mut ${z(t.schemaName)}, _cap: &UpgradeCap) {
67
- ${t.fields.map(l=>{let r="";return l.type.includes("StorageValue")?r="storage_value::new()":l.type.includes("StorageMap")?r="storage_map::new()":l.type.includes("StorageDoubleMap")&&(r="storage_double_map::new()"),`storage_migrate::add_field<${l.type}>(&mut ${t.schemaName}.id, b"${l.name}", ${r});`}).join("")}
49
+ `),process.exit(0)}},pe=tt;import{schemaGen as ot,loadConfig as nt}from"@0xobelisk/sui-common";import st from"chalk";var rt={command:"schemagen",describe:"Autogenerate Dubhe schemas based on the config file",builder:{"config-path":{type:"string",default:"dubhe.config.ts",desc:"Path to the config file"},network:{type:"string",choices:["mainnet","testnet","devnet","localnet"],desc:"Node network (mainnet/testnet/devnet/localnet)"},"framework-id":{type:"string",desc:"Framework Package ID"}},async handler({"config-path":e,network:t,"framework-id":o}){try{let s=await nt(e);await ot(s,void 0,t,o),process.exit(0)}catch(s){console.log(st.red("Schemagen failed!")),console.error(s.message)}}},ue=rt;import{loadConfig as at}from"@0xobelisk/sui-common";var it={command:"publish",describe:"Publish dubhe move contract",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet"],desc:"Node network (mainnet/testnet/devnet/localnet)"},"config-path":{type:"string",default:"dubhe.config.ts",desc:"Configuration file path"},"contract-name":{type:"string",desc:"Optional contract name in contracts/ directory"}})},async handler({network:e,"config-path":t,"contract-name":o}){try{let s=await at(t);await ae(s,e,o)}catch(s){D(s),process.exit(1)}process.exit(0)}},ge=it;import{Dubhe as ct}from"@0xobelisk/sui-client";import{Transaction as lt,UpgradePolicy as dt}from"@mysten/sui/transactions";import{getFullnodeUrl as pt,SuiClient as ut}from"@mysten/sui/client";import{execSync as gt}from"child_process";import z from"chalk";import*as F from"fs";import*as me from"path";function mt(e,t){t.forEach(o=>{let s=`${e}/sources/codegen/schemas/${o.schemaName}.move`,n=F.readFileSync(s,"utf-8"),c=new RegExp(`public fun migrate\\(_${o.schemaName}: &mut ${J(o.schemaName)}, _cap: &UpgradeCap\\) {[^}]*}`),a=`
50
+ public fun migrate(${o.schemaName}: &mut ${J(o.schemaName)}, _cap: &UpgradeCap) {
51
+ ${o.fields.map(d=>{let r="";return d.type.includes("StorageValue")?r="storage_value::new()":d.type.includes("StorageMap")?r="storage_map::new()":d.type.includes("StorageDoubleMap")&&(r="storage_double_map::new()"),`storage_migrate::add_field<${d.type}>(&mut ${o.schemaName}.id, b"${d.name}", ${r});`}).join("")}
68
52
  }
69
- `,d=n.replace(u,c);M.writeFileSync(s,d,"utf-8")})}function z(e){return e.split("_").map((o,t)=>o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()).join("")}function yo(e){let o=e.split("::");return o.length>0?o[o.length-1]:""}function Y(e,o,t,s){let n=fe.resolve(e),c=M.readFileSync(n,"utf-8").split(`
70
- `),d=c.findIndex(p=>p.trim()===`[env.${o}]`);if(d===-1)return console.log(`Network type [env.${o}] not found in the file.`),"";let l=-1,r="";for(let p=d+1;p<c.length;p++){let f=c[p].trim();if(f.startsWith("["))break;if(f.startsWith(t)){l=p,r=f.split("=")[1].trim().replace(/"/g,"");break}}if(l!==-1){c[l]=`${t} = "${s}"`;let p=c.join(`
71
- `);M.writeFileSync(n,p,"utf-8")}else console.log(`${t} not found for [env.${o}].`);return r}async function he(e,o,t){await H(t);let s=process.cwd(),n=`${s}/contracts/${o}`,u=process.env.PRIVATE_KEY;if(!u)throw new w(`Missing PRIVATE_KEY environment variable.
53
+ `,p=n.replace(c,a);F.writeFileSync(s,p,"utf-8")})}function J(e){return e.split("_").map((t,o)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function ft(e){let t=e.split("::");return t.length>0?t[t.length-1]:""}function B(e,t,o,s){let n=me.resolve(e),a=F.readFileSync(n,"utf-8").split(`
54
+ `),p=a.findIndex(u=>u.trim()===`[env.${t}]`);if(p===-1)return console.log(`Network type [env.${t}] not found in the file.`),"";let d=-1,r="";for(let u=p+1;u<a.length;u++){let f=a[u].trim();if(f.startsWith("["))break;if(f.startsWith(o)){d=u,r=f.split("=")[1].trim().replace(/"/g,"");break}}if(d!==-1){a[d]=`${o} = "${s}"`;let u=a.join(`
55
+ `);F.writeFileSync(n,u,"utf-8")}else console.log(`${o} not found for [env.${t}].`);return r}async function fe(e,t,o){await M(o);let s=process.cwd(),n=`${s}/contracts/${t}`,c=process.env.PRIVATE_KEY;if(!c)throw new y(`Missing PRIVATE_KEY environment variable.
72
56
  Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
73
- in your contracts directory to use the default sui private key.`);let c=N(u);if(c===!1)throw new w("Please check your privateKey.");let l=new lo({secretKey:c}).getKeypair(),r=new mo({url:go(t)}),p=Number(await ee(n,t)),f=await oe(n,t),h=await j(n,t),b=await te(n,t),C=Y(`${n}/Move.lock`,t,"original-published-id","0x0000000000000000000000000000000000000000000000000000000000000000"),_=[],v=await X(n,t);for(let a in e.schemas)v.forEach(g=>{if(z(a)==yo(g.name)){let I={schemaName:"",fields:[]},m=[],i=!1;for(let x in e.schemas[a].structure)x in g.structure||(i=!0,m.push({name:x,type:e.schemas[a].structure[x]}),g.structure[x]=e.schemas[a].structure[x]);i&&(I.schemaName=a,I.fields=m,_.push(I))}});_.forEach(a=>{console.log(`
74
- \u{1F680} Starting Migration for ${a.schemaName}...`),console.log("\u{1F4CB} Migration Fields:",a.fields)}),ho(n,_);try{let a,g,I;try{let{modules:P,dependencies:xe,digest:ke}=JSON.parse(fo(`sui move build --dump-bytecode-as-base64 --path ${s}/contracts/${o}`,{encoding:"utf-8"}));a=P,g=xe,I=ke}catch(P){throw new T(P.stdout)}console.log(`
75
- \u{1F680} Starting Upgrade Process...`),console.log("\u{1F4CB} OldPackageId:",f),console.log("\u{1F4CB} UpgradeCap Object Id:",b),console.log("\u{1F4CB} OldVersion:",p);let m=new uo,i=m.moveCall({target:"0x2::package::authorize_upgrade",arguments:[m.object(b),m.pure.u8(po.COMPATIBLE),m.pure.vector("u8",I)]}),x=m.upgrade({modules:a,dependencies:g,package:f,ticket:i});m.moveCall({target:"0x2::package::commit_upgrade",arguments:[m.object(b),x]});let F=await r.signAndExecuteTransaction({signer:l,transaction:m,options:{showObjectChanges:!0}}),G="";F.objectChanges.map(P=>{P.type==="published"&&(console.log(B.blue(`${o} PackageId: ${P.packageId}`)),console.log(B.blue(`${o} Version: ${p+1}`)),G=P.packageId)}),Y(`${n}/Move.lock`,t,"original-published-id",C),Y(`${n}/Move.lock`,t,"latest-published-id",G),Y(`${n}/Move.lock`,t,"published-version",p+1+""),console.log(B.green(`Upgrade Transaction Digest: ${F.digest}`)),A(o,t,G,b,h,p+1,v)}catch(a){console.log(B.red("Upgrade failed!")),console.error(a.message)}}import{loadConfig as bo}from"@0xobelisk/sui-common";var _o={command:"upgrade",describe:"Upgrade your move contracts",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet"],desc:"Network of the node (mainnet/testnet/devnet/localnet)"},configPath:{type:"string",default:"dubhe.config.ts",decs:"Path to the config file"}})},async handler({network:e,configPath:o}){try{let t=await bo(o);await he(t,t.name,e)}catch(t){D(t),process.exit(1)}process.exit(0)}},ye=_o;import{execSync as wo}from"child_process";import vo from"chalk";var Co={command:"test",describe:"Run tests in Dubhe contracts",builder(e){return e.options({packagePath:{type:"string",default:".",description:"Options to pass to forge test"}})},async handler({packagePath:e}){try{wo(`sui move test --path ${e}`,{encoding:"utf-8"})}catch(o){console.error(vo.red("Error executing sui move test:")),console.log(o.stdout),process.exit(0)}}},be=Co;var xo={command:"hello",describe:"hello, dubhe",builder(e){return e},async handler(){de()}},_e=xo;var we=[me,ue,pe,ge,ye,be,_e];import*as Ce from"dotenv";import ve from"chalk";Ce.config();ko(So(process.argv)).scriptName("dubhe").command(we).strict().fail((e,o)=>{console.error(ve.red(e)),e.includes("Missing required argument")&&console.log(ve.yellow(`Run 'pnpm dubhe ${process.argv[2]} --help' for a list of available and required arguments.`)),console.log(""),D(o),console.log(""),process.exit(1)}).alias({h:"help"}).argv;
57
+ in your contracts directory to use the default sui private key.`);let a=I(c);if(a===!1)throw new y("Please check your privateKey.");let d=new ct({secretKey:a}).getKeypair(),r=new ut({url:pt(o)}),u=Number(await Q(n,o)),f=await ee(n,o),h=await q(n,o),b=await te(n,o),x=B(`${n}/Move.lock`,o,"original-published-id","0x0000000000000000000000000000000000000000000000000000000000000000"),v=[],_=await X(n,o);for(let i in e.schemas)_.forEach(g=>{if(J(i)==ft(g.name)){let $={schemaName:"",fields:[]},m=[],l=!1;for(let C in e.schemas[i].structure)C in g.structure||(l=!0,m.push({name:C,type:e.schemas[i].structure[C]}),g.structure[C]=e.schemas[i].structure[C]);l&&($.schemaName=i,$.fields=m,v.push($))}});v.forEach(i=>{console.log(`
58
+ \u{1F680} Starting Migration for ${i.schemaName}...`),console.log("\u{1F4CB} Migration Fields:",i.fields)}),mt(n,v);try{let i,g,$;try{let{modules:P,dependencies:Ce,digest:$e}=JSON.parse(gt(`sui move build --dump-bytecode-as-base64 --path ${s}/contracts/${t}`,{encoding:"utf-8"}));i=P,g=Ce,$=$e}catch(P){throw new U(P.stdout)}console.log(`
59
+ \u{1F680} Starting Upgrade Process...`),console.log("\u{1F4CB} OldPackageId:",f),console.log("\u{1F4CB} UpgradeCap Object Id:",b),console.log("\u{1F4CB} OldVersion:",u);let m=new lt,l=m.moveCall({target:"0x2::package::authorize_upgrade",arguments:[m.object(b),m.pure.u8(dt.COMPATIBLE),m.pure.vector("u8",$)]}),C=m.upgrade({modules:i,dependencies:g,package:f,ticket:l});m.moveCall({target:"0x2::package::commit_upgrade",arguments:[m.object(b),C]});let O=await r.signAndExecuteTransaction({signer:d,transaction:m,options:{showObjectChanges:!0}}),H="";O.objectChanges.map(P=>{P.type==="published"&&(console.log(z.blue(`${t} PackageId: ${P.packageId}`)),console.log(z.blue(`${t} Version: ${u+1}`)),H=P.packageId)}),B(`${n}/Move.lock`,o,"original-published-id",x),B(`${n}/Move.lock`,o,"latest-published-id",H),B(`${n}/Move.lock`,o,"published-version",u+1+""),console.log(z.green(`Upgrade Transaction Digest: ${O.digest}`)),R(t,o,H,b,h,u+1,_)}catch(i){console.log(z.red("Upgrade failed!")),console.error(i.message)}}import{loadConfig as ht}from"@0xobelisk/sui-common";var yt={command:"upgrade",describe:"Upgrade your move contracts",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet"],desc:"Network of the node (mainnet/testnet/devnet/localnet)"},"config-path":{type:"string",default:"dubhe.config.ts",decs:"Path to the config file"}})},async handler({network:e,"config-path":t}){try{let o=await ht(t);await fe(o,o.name,e)}catch(o){D(o),process.exit(1)}process.exit(0)}},he=yt;import{execSync as bt}from"child_process";import vt from"chalk";import{loadConfig as _t}from"@0xobelisk/sui-common";var wt={command:"test",describe:"Run tests in Dubhe contracts",builder(e){return e.options({"config-path":{type:"string",default:"dubhe.config.ts",description:"Options to pass to forge test"},test:{type:"string",desc:"Run a specific test"}})},async handler({"config-path":e,test:t}){try{console.log("\u{1F680} Running move test");let o=await _t(e),c=`sui move test --path ${`${process.cwd()}/contracts/${o.name}`} ${t?` --test ${t}`:""}`,a=bt(c,{encoding:"utf-8"});console.log(a)}catch(o){console.error(vt.red("Error executing sui move test:")),console.log(o.stdout),process.exit(0)}}},ye=wt;import{execSync as xt}from"child_process";import Ct from"chalk";import{loadConfig as $t}from"@0xobelisk/sui-common";var kt={command:"build",describe:"Run tests in Dubhe contracts",builder(e){return e.options({"config-path":{type:"string",default:"dubhe.config.ts",description:"Options to pass to forge test"},network:{type:"string",choices:["mainnet","testnet","devnet","localnet"],desc:"Node network (mainnet/testnet/devnet/localnet)"},"dump-bytecode-as-base64":{type:"boolean",default:!1,desc:"Dump bytecode as base64"}})},async handler({"config-path":e,network:t,"dump-bytecode-as-base64":o}){try{console.log("\u{1F680} Running move build");let s=await $t(e),c=`${process.cwd()}/contracts/${s.name}`;await M(t),L(c+"/Move.toml",t);let a=`sui move build --path ${c} ${o?" --dump-bytecode-as-base64":""}`,p=xt(a,{encoding:"utf-8"});console.log(p)}catch(s){console.error(Ct.red("Error executing sui move build:")),console.log(s.stdout),process.exit(0)}}},be=kt;var It={command:"hello",describe:"hello, dubhe",builder(e){return e},async handler(){N()}},ve=It;var _e=[ge,de,pe,ue,he,ye,be,ve];import*as xe from"dotenv";import we from"chalk";xe.config();Et(St(process.argv)).scriptName("dubhe").command(_e).strict().fail((e,t)=>{console.error(we.red(e)),e.includes("Missing required argument")&&console.log(we.yellow(`Run 'pnpm dubhe ${process.argv[2]} --help' for a list of available and required arguments.`)),console.log(""),D(t),console.log(""),process.exit(1)}).alias({h:"help"}).argv;
76
60
  //# sourceMappingURL=dubhe.js.map