From 338a32b4def852b708b66cafdf372384df3228ea Mon Sep 17 00:00:00 2001 From: 0xaptosj <129789810+0xaptosj@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:45:17 -0700 Subject: [PATCH 1/3] publish contract to object instead of account --- pnpm-lock.yaml | 217 ++++++++++-------- templates/digital-asset-template/package.json | 5 +- .../scripts/move/publish.js | 63 +++-- .../scripts/move/upgrade.js | 35 +++ .../scripts/update_env.js | 31 --- .../fungible-asset-template/package.json | 5 +- .../scripts/move/publish.js | 54 +++-- .../scripts/move/upgrade.js | 35 +++ .../scripts/update_env.js | 31 --- 9 files changed, 281 insertions(+), 195 deletions(-) create mode 100644 templates/digital-asset-template/scripts/move/upgrade.js delete mode 100644 templates/digital-asset-template/scripts/update_env.js create mode 100644 templates/fungible-asset-template/scripts/move/upgrade.js delete mode 100644 templates/fungible-asset-template/scripts/update_env.js diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d96cf53..e9f41383 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,114 +1,169 @@ -lockfileVersion: '6.0' +lockfileVersion: '9.0' settings: autoInstallPeers: true excludeLinksFromLockfile: false -dependencies: - kolorist: - specifier: ^1.8.0 - version: 1.8.0 - ora: - specifier: ^8.0.1 - version: 8.0.1 - prompts: - specifier: ^2.4.2 - version: 2.4.2 - typescript: - specifier: ^4.7.4 - version: 4.9.5 - -devDependencies: - '@types/node': - specifier: ^20.5.0 - version: 20.14.2 +importers: + + .: + dependencies: + kolorist: + specifier: ^1.8.0 + version: 1.8.0 + ora: + specifier: ^8.0.1 + version: 8.0.1 + prompts: + specifier: ^2.4.2 + version: 2.4.2 + typescript: + specifier: ^4.7.4 + version: 4.9.5 + devDependencies: + '@types/node': + specifier: ^20.5.0 + version: 20.14.2 packages: - /@types/node@20.14.2: + '@types/node@20.14.2': resolution: {integrity: sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==} - dependencies: - undici-types: 5.26.5 - dev: true - /ansi-regex@6.0.1: + ansi-regex@6.0.1: resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} engines: {node: '>=12'} - dev: false - /chalk@5.3.0: + chalk@5.3.0: resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - dev: false - /cli-cursor@4.0.0: + cli-cursor@4.0.0: resolution: {integrity: sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - restore-cursor: 4.0.0 - dev: false - /cli-spinners@2.9.2: + cli-spinners@2.9.2: resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==} engines: {node: '>=6'} - dev: false - /emoji-regex@10.3.0: + emoji-regex@10.3.0: resolution: {integrity: sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==} - dev: false - /get-east-asian-width@1.2.0: + get-east-asian-width@1.2.0: resolution: {integrity: sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==} engines: {node: '>=18'} - dev: false - /is-interactive@2.0.0: + is-interactive@2.0.0: resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} engines: {node: '>=12'} - dev: false - /is-unicode-supported@1.3.0: + is-unicode-supported@1.3.0: resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} engines: {node: '>=12'} - dev: false - /is-unicode-supported@2.0.0: + is-unicode-supported@2.0.0: resolution: {integrity: sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==} engines: {node: '>=18'} - dev: false - /kleur@3.0.3: + kleur@3.0.3: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - dev: false - /kolorist@1.8.0: + kolorist@1.8.0: resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==} - dev: false - /log-symbols@6.0.0: + log-symbols@6.0.0: resolution: {integrity: sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==} engines: {node: '>=18'} - dependencies: - chalk: 5.3.0 - is-unicode-supported: 1.3.0 - dev: false - /mimic-fn@2.1.0: + mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} - dev: false - /onetime@5.1.2: + onetime@5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} - dependencies: - mimic-fn: 2.1.0 - dev: false - /ora@8.0.1: + ora@8.0.1: resolution: {integrity: sha512-ANIvzobt1rls2BDny5fWZ3ZVKyD6nscLvfFRpQgfWsythlcsVUC9kL0zq6j2Z5z9wwp1kd7wpsD/T9qNPVLCaQ==} engines: {node: '>=18'} + + prompts@2.4.2: + resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} + engines: {node: '>= 6'} + + restore-cursor@4.0.0: + resolution: {integrity: sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + + signal-exit@3.0.7: + resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + + sisteransi@1.0.5: + resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + + stdin-discarder@0.2.2: + resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==} + engines: {node: '>=18'} + + string-width@7.1.0: + resolution: {integrity: sha512-SEIJCWiX7Kg4c129n48aDRwLbFb2LJmXXFrWBG4NGaRtMQ3myKPKbwrD1BKqQn74oCoNMBVrfDEr5M9YxCsrkw==} + engines: {node: '>=18'} + + strip-ansi@7.1.0: + resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} + engines: {node: '>=12'} + + typescript@4.9.5: + resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} + engines: {node: '>=4.2.0'} + hasBin: true + + undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + +snapshots: + + '@types/node@20.14.2': + dependencies: + undici-types: 5.26.5 + + ansi-regex@6.0.1: {} + + chalk@5.3.0: {} + + cli-cursor@4.0.0: + dependencies: + restore-cursor: 4.0.0 + + cli-spinners@2.9.2: {} + + emoji-regex@10.3.0: {} + + get-east-asian-width@1.2.0: {} + + is-interactive@2.0.0: {} + + is-unicode-supported@1.3.0: {} + + is-unicode-supported@2.0.0: {} + + kleur@3.0.3: {} + + kolorist@1.8.0: {} + + log-symbols@6.0.0: + dependencies: + chalk: 5.3.0 + is-unicode-supported: 1.3.0 + + mimic-fn@2.1.0: {} + + onetime@5.1.2: + dependencies: + mimic-fn: 2.1.0 + + ora@8.0.1: dependencies: chalk: 5.3.0 cli-cursor: 4.0.0 @@ -119,59 +174,33 @@ packages: stdin-discarder: 0.2.2 string-width: 7.1.0 strip-ansi: 7.1.0 - dev: false - /prompts@2.4.2: - resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} - engines: {node: '>= 6'} + prompts@2.4.2: dependencies: kleur: 3.0.3 sisteransi: 1.0.5 - dev: false - /restore-cursor@4.0.0: - resolution: {integrity: sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + restore-cursor@4.0.0: dependencies: onetime: 5.1.2 signal-exit: 3.0.7 - dev: false - /signal-exit@3.0.7: - resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} - dev: false + signal-exit@3.0.7: {} - /sisteransi@1.0.5: - resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} - dev: false + sisteransi@1.0.5: {} - /stdin-discarder@0.2.2: - resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==} - engines: {node: '>=18'} - dev: false + stdin-discarder@0.2.2: {} - /string-width@7.1.0: - resolution: {integrity: sha512-SEIJCWiX7Kg4c129n48aDRwLbFb2LJmXXFrWBG4NGaRtMQ3myKPKbwrD1BKqQn74oCoNMBVrfDEr5M9YxCsrkw==} - engines: {node: '>=18'} + string-width@7.1.0: dependencies: emoji-regex: 10.3.0 get-east-asian-width: 1.2.0 strip-ansi: 7.1.0 - dev: false - /strip-ansi@7.1.0: - resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} - engines: {node: '>=12'} + strip-ansi@7.1.0: dependencies: ansi-regex: 6.0.1 - dev: false - /typescript@4.9.5: - resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} - engines: {node: '>=4.2.0'} - hasBin: true - dev: false + typescript@4.9.5: {} - /undici-types@5.26.5: - resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} - dev: true + undici-types@5.26.5: {} diff --git a/templates/digital-asset-template/package.json b/templates/digital-asset-template/package.json index 17c9ce9d..976a608c 100644 --- a/templates/digital-asset-template/package.json +++ b/templates/digital-asset-template/package.json @@ -4,10 +4,11 @@ "version": "0.0.0", "license": "Apache-2.0", "scripts": { - "move:init": "node ./scripts/init && node ./scripts/update_env", + "move:init": "node ./scripts/init", "move:test": "node ./scripts/move/test", "move:compile": "node ./scripts/move/compile", "move:publish": "node ./scripts/move/publish", + "move:upgrade": "node ./scripts/move/upgrade", "dev": "vite", "build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", @@ -16,7 +17,7 @@ "fmt": "npm run _fmt -- --write" }, "dependencies": { - "@aptos-labs/ts-sdk": "1.20.0", + "@aptos-labs/ts-sdk": "1.22.1", "@aptos-labs/wallet-adapter-react": "^3.3.0", "@irys/sdk": "^0.2.1", "@radix-ui/react-accordion": "^1.1.2", diff --git a/templates/digital-asset-template/scripts/move/publish.js b/templates/digital-asset-template/scripts/move/publish.js index f853acb0..448e2fca 100644 --- a/templates/digital-asset-template/scripts/move/publish.js +++ b/templates/digital-asset-template/scripts/move/publish.js @@ -4,32 +4,55 @@ const yaml = require("js-yaml"); const cli = require("@aptos-labs/ts-sdk/dist/common/cli/index.js"); const config = yaml.load(fs.readFileSync("./.aptos/config.yaml", "utf8")); -const accountAddress = - config["profiles"][process.env.PROJECT_NAME]["account"]; +const accountAddress = config["profiles"][process.env.PROJECT_NAME]["account"]; async function publish() { if (!process.env.VITE_COLLECTION_CREATOR_ADDRESS) { - throw new Error( - "VITE_COLLECTION_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file" - ); + throw new Error("VITE_COLLECTION_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file"); } const move = new cli.Move(); - await move.publish({ - packageDirectoryPath: "move", - namedAddresses: { - // Publish module to account address - launchpad_addr: accountAddress, - // This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra - initial_creator_addr: process.env.VITE_COLLECTION_CREATOR_ADDRESS, - // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages - // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ - // Please find it on the network you are using, This is testnet deployment - minter: - "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", - }, - profile: `${process.env.PROJECT_NAME}-${process.env.VITE_APP_NETWORK}`, - }); + move + .createObjectAndPublishPackage({ + packageDirectoryPath: "move", + addressName: "launchpad_addr", + namedAddresses: { + // Publish module to new object, but since we create the object on the fly, we fill in the publisher's account address here + launchpad_addr: accountAddress, + // This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra + initial_creator_addr: process.env.VITE_COLLECTION_CREATOR_ADDRESS, + // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages + // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ + // Please find it on the network you are using, This is testnet deployment + minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", + }, + profile: `${process.env.PROJECT_NAME}-${process.env.VITE_APP_NETWORK}`, + }) + .then((objectAddress) => { + const filePath = ".env"; + let envContent = ""; + + // Check .env file exists and read it + if (fs.existsSync(filePath)) { + envContent = fs.readFileSync(filePath, "utf8"); + } + + // Regular expression to match the VITE_MODULE_ADDRESS variable + const regex = /^VITE_MODULE_ADDRESS=.*$/m; + const newEntry = `VITE_MODULE_ADDRESS=${objectAddress}`; + + // Check if VITE_MODULE_ADDRESS is already defined + if (envContent.match(regex)) { + // If the variable exists, replace it with the new value + envContent = envContent.replace(regex, newEntry); + } else { + // If the variable does not exist, append it + envContent += `\n${newEntry}`; + } + + // Write the updated content back to the .env file + fs.writeFileSync(filePath, envContent, "utf8"); + }); } publish(); diff --git a/templates/digital-asset-template/scripts/move/upgrade.js b/templates/digital-asset-template/scripts/move/upgrade.js new file mode 100644 index 00000000..8fc5c201 --- /dev/null +++ b/templates/digital-asset-template/scripts/move/upgrade.js @@ -0,0 +1,35 @@ +require("dotenv").config(); +const cli = require("@aptos-labs/ts-sdk/dist/common/cli/index.js"); + +async function publish() { + if (!process.env.VITE_COLLECTION_CREATOR_ADDRESS) { + throw new Error("VITE_COLLECTION_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file"); + } + + if (!process.env.VITE_MODULE_ADDRESS) { + throw new Error( + "VITE_MODULE_ADDRESS variable is not set, make sure you have published the module before upgrading it", + ); + } + + const move = new cli.Move(); + + move + .upgradeObjectPackage({ + packageDirectoryPath: "move", + objectAddress: process.env.VITE_MODULE_ADDRESS, + namedAddresses: { + // Upgrade module from an object + launchpad_addr: process.env.VITE_MODULE_ADDRESS, + // This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra + initial_creator_addr: process.env.VITE_COLLECTION_CREATOR_ADDRESS, + // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages + // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ + // Please find it on the network you are using, This is testnet deployment + minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", + }, + profile: process.env.VITE_APP_NETWORK, + }) + .then(console.log); +} +publish(); diff --git a/templates/digital-asset-template/scripts/update_env.js b/templates/digital-asset-template/scripts/update_env.js deleted file mode 100644 index f23402db..00000000 --- a/templates/digital-asset-template/scripts/update_env.js +++ /dev/null @@ -1,31 +0,0 @@ -const fs = require("node:fs"); -const yaml = require("js-yaml"); -require("dotenv").config(); - -const config = yaml.load(fs.readFileSync("./.aptos/config.yaml", "utf8")); -const accountAddress = - config["profiles"][process.env.PROJECT_NAME]["account"]; - -const filePath = ".env"; -let envContent = ""; - -// Check .env file exists and read it -if (fs.existsSync(filePath)) { - envContent = fs.readFileSync(filePath, "utf8"); -} - -// Regular expression to match the VITE_MODULE_ADDRESS variable -const regex = /^VITE_MODULE_ADDRESS=.*$/m; -const newEntry = `VITE_MODULE_ADDRESS=0x${accountAddress}`; - -// Check if VITE_MODULE_ADDRESS is already defined -if (envContent.match(regex)) { - // If the variable exists, replace it with the new value - envContent = envContent.replace(regex, newEntry); -} else { - // If the variable does not exist, append it - envContent += `\n${newEntry}`; -} - -// Write the updated content back to the .env file -fs.writeFileSync(filePath, envContent, "utf8"); diff --git a/templates/fungible-asset-template/package.json b/templates/fungible-asset-template/package.json index 30f11462..4c1a771e 100644 --- a/templates/fungible-asset-template/package.json +++ b/templates/fungible-asset-template/package.json @@ -4,10 +4,11 @@ "version": "0.0.0", "license": "Apache-2.0", "scripts": { - "move:init": "node ./scripts/init && node ./scripts/update_env", + "move:init": "node ./scripts/init", "move:test": "node ./scripts/move/test", "move:compile": "node ./scripts/move/compile", "move:publish": "node ./scripts/move/publish", + "move:upgrade": "node ./scripts/move/upgrade", "dev": "vite", "build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", @@ -16,7 +17,7 @@ "fmt": "npm run _fmt -- --write" }, "dependencies": { - "@aptos-labs/ts-sdk": "^1.20.0", + "@aptos-labs/ts-sdk": "1.22.1", "@aptos-labs/wallet-adapter-react": "^3.3.0", "@irys/sdk": "^0.2.1", "@radix-ui/react-accordion": "^1.1.2", diff --git a/templates/fungible-asset-template/scripts/move/publish.js b/templates/fungible-asset-template/scripts/move/publish.js index 76c24862..0531936d 100644 --- a/templates/fungible-asset-template/scripts/move/publish.js +++ b/templates/fungible-asset-template/scripts/move/publish.js @@ -4,26 +4,50 @@ const yaml = require("js-yaml"); const cli = require("@aptos-labs/ts-sdk/dist/common/cli/index.js"); const config = yaml.load(fs.readFileSync("./.aptos/config.yaml", "utf8")); -const accountAddress = - config["profiles"][process.env.PROJECT_NAME]["account"]; +const accountAddress = config["profiles"][process.env.PROJECT_NAME]["account"]; async function publish() { if (!process.env.VITE_FA_CREATOR_ADDRESS) { - throw new Error( - "VITE_FA_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file" - ); + throw new Error("VITE_FA_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file"); } const move = new cli.Move(); - await move.publish({ - packageDirectoryPath: "move", - namedAddresses: { - // Publish module to account address - launchpad_addr: accountAddress, - // This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra - initial_creator_addr: process.env.VITE_FA_CREATOR_ADDRESS, - }, - profile: `${process.env.PROJECT_NAME}-${process.env.VITE_APP_NETWORK}`, - }); + move + .createObjectAndPublishPackage({ + packageDirectoryPath: "move", + addressName: "launchpad_addr", + namedAddresses: { + // Publish module to account address + launchpad_addr: accountAddress, + // This is the address you want to use to create fungible asset with, e.g. an address in Petra so you can create fungible asset in UI using Petra + initial_creator_addr: process.env.VITE_FA_CREATOR_ADDRESS, + }, + profile: `${process.env.PROJECT_NAME}-${process.env.VITE_APP_NETWORK}`, + }) + .then((objectAddress) => { + const filePath = ".env"; + let envContent = ""; + + // Check .env file exists and read it + if (fs.existsSync(filePath)) { + envContent = fs.readFileSync(filePath, "utf8"); + } + + // Regular expression to match the VITE_MODULE_ADDRESS variable + const regex = /^VITE_MODULE_ADDRESS=.*$/m; + const newEntry = `VITE_MODULE_ADDRESS=${objectAddress}`; + + // Check if VITE_MODULE_ADDRESS is already defined + if (envContent.match(regex)) { + // If the variable exists, replace it with the new value + envContent = envContent.replace(regex, newEntry); + } else { + // If the variable does not exist, append it + envContent += `\n${newEntry}`; + } + + // Write the updated content back to the .env file + fs.writeFileSync(filePath, envContent, "utf8"); + }); } publish(); diff --git a/templates/fungible-asset-template/scripts/move/upgrade.js b/templates/fungible-asset-template/scripts/move/upgrade.js new file mode 100644 index 00000000..3b09947a --- /dev/null +++ b/templates/fungible-asset-template/scripts/move/upgrade.js @@ -0,0 +1,35 @@ +require("dotenv").config(); +const cli = require("@aptos-labs/ts-sdk/dist/common/cli/index.js"); + +async function publish() { + if (!process.env.VITE_FA_CREATOR_ADDRESS) { + throw new Error("VITE_FA_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file"); + } + + if (!process.env.VITE_MODULE_ADDRESS) { + throw new Error( + "VITE_MODULE_ADDRESS variable is not set, make sure you have published the module before upgrading it", + ); + } + + const move = new cli.Move(); + + move + .upgradeObjectPackage({ + packageDirectoryPath: "move", + objectAddress: process.env.VITE_MODULE_ADDRESS, + namedAddresses: { + // Upgrade module from an object + launchpad_addr: process.env.VITE_MODULE_ADDRESS, + // This is the address you want to use to create fungible asset with, e.g. an address in Petra so you can create fungible asset in UI using Petra + initial_creator_addr: process.env.VITE_FA_CREATOR_ADDRESS, + // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages + // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ + // Please find it on the network you are using, This is testnet deployment + minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", + }, + profile: process.env.VITE_APP_NETWORK, + }) + .then(console.log); +} +publish(); diff --git a/templates/fungible-asset-template/scripts/update_env.js b/templates/fungible-asset-template/scripts/update_env.js deleted file mode 100644 index f23402db..00000000 --- a/templates/fungible-asset-template/scripts/update_env.js +++ /dev/null @@ -1,31 +0,0 @@ -const fs = require("node:fs"); -const yaml = require("js-yaml"); -require("dotenv").config(); - -const config = yaml.load(fs.readFileSync("./.aptos/config.yaml", "utf8")); -const accountAddress = - config["profiles"][process.env.PROJECT_NAME]["account"]; - -const filePath = ".env"; -let envContent = ""; - -// Check .env file exists and read it -if (fs.existsSync(filePath)) { - envContent = fs.readFileSync(filePath, "utf8"); -} - -// Regular expression to match the VITE_MODULE_ADDRESS variable -const regex = /^VITE_MODULE_ADDRESS=.*$/m; -const newEntry = `VITE_MODULE_ADDRESS=0x${accountAddress}`; - -// Check if VITE_MODULE_ADDRESS is already defined -if (envContent.match(regex)) { - // If the variable exists, replace it with the new value - envContent = envContent.replace(regex, newEntry); -} else { - // If the variable does not exist, append it - envContent += `\n${newEntry}`; -} - -// Write the updated content back to the .env file -fs.writeFileSync(filePath, envContent, "utf8"); From df9317e5cf2bcedeb8af32824a5935d52182e8b3 Mon Sep 17 00:00:00 2001 From: 0xaptosj <129789810+0xaptosj@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:08:03 -0700 Subject: [PATCH 2/3] remove console log --- .../scripts/move/upgrade.js | 32 +++++++++---------- .../scripts/move/upgrade.js | 32 +++++++++---------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/templates/digital-asset-template/scripts/move/upgrade.js b/templates/digital-asset-template/scripts/move/upgrade.js index 8fc5c201..0fe9f442 100644 --- a/templates/digital-asset-template/scripts/move/upgrade.js +++ b/templates/digital-asset-template/scripts/move/upgrade.js @@ -14,22 +14,20 @@ async function publish() { const move = new cli.Move(); - move - .upgradeObjectPackage({ - packageDirectoryPath: "move", - objectAddress: process.env.VITE_MODULE_ADDRESS, - namedAddresses: { - // Upgrade module from an object - launchpad_addr: process.env.VITE_MODULE_ADDRESS, - // This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra - initial_creator_addr: process.env.VITE_COLLECTION_CREATOR_ADDRESS, - // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages - // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ - // Please find it on the network you are using, This is testnet deployment - minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", - }, - profile: process.env.VITE_APP_NETWORK, - }) - .then(console.log); + move.upgradeObjectPackage({ + packageDirectoryPath: "move", + objectAddress: process.env.VITE_MODULE_ADDRESS, + namedAddresses: { + // Upgrade module from an object + launchpad_addr: process.env.VITE_MODULE_ADDRESS, + // This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra + initial_creator_addr: process.env.VITE_COLLECTION_CREATOR_ADDRESS, + // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages + // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ + // Please find it on the network you are using, This is testnet deployment + minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", + }, + profile: process.env.VITE_APP_NETWORK, + }); } publish(); diff --git a/templates/fungible-asset-template/scripts/move/upgrade.js b/templates/fungible-asset-template/scripts/move/upgrade.js index 3b09947a..716c6448 100644 --- a/templates/fungible-asset-template/scripts/move/upgrade.js +++ b/templates/fungible-asset-template/scripts/move/upgrade.js @@ -14,22 +14,20 @@ async function publish() { const move = new cli.Move(); - move - .upgradeObjectPackage({ - packageDirectoryPath: "move", - objectAddress: process.env.VITE_MODULE_ADDRESS, - namedAddresses: { - // Upgrade module from an object - launchpad_addr: process.env.VITE_MODULE_ADDRESS, - // This is the address you want to use to create fungible asset with, e.g. an address in Petra so you can create fungible asset in UI using Petra - initial_creator_addr: process.env.VITE_FA_CREATOR_ADDRESS, - // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages - // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ - // Please find it on the network you are using, This is testnet deployment - minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", - }, - profile: process.env.VITE_APP_NETWORK, - }) - .then(console.log); + move.upgradeObjectPackage({ + packageDirectoryPath: "move", + objectAddress: process.env.VITE_MODULE_ADDRESS, + namedAddresses: { + // Upgrade module from an object + launchpad_addr: process.env.VITE_MODULE_ADDRESS, + // This is the address you want to use to create fungible asset with, e.g. an address in Petra so you can create fungible asset in UI using Petra + initial_creator_addr: process.env.VITE_FA_CREATOR_ADDRESS, + // Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages + // You can read the source code of it here: https://github.com/aptos-labs/token-minter/ + // Please find it on the network you are using, This is testnet deployment + minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", + }, + profile: process.env.VITE_APP_NETWORK, + }); } publish(); From c39d11acdccc33762722402d881bfece187a4254 Mon Sep 17 00:00:00 2001 From: 0xaptosj <129789810+0xaptosj@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:15:49 -0700 Subject: [PATCH 3/3] fix --- templates/digital-asset-template/scripts/move/upgrade.js | 2 +- templates/fungible-asset-template/scripts/move/upgrade.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/digital-asset-template/scripts/move/upgrade.js b/templates/digital-asset-template/scripts/move/upgrade.js index 0fe9f442..39ac2eb5 100644 --- a/templates/digital-asset-template/scripts/move/upgrade.js +++ b/templates/digital-asset-template/scripts/move/upgrade.js @@ -27,7 +27,7 @@ async function publish() { // Please find it on the network you are using, This is testnet deployment minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", }, - profile: process.env.VITE_APP_NETWORK, + profile: process.env.PROFILE_NAME, }); } publish(); diff --git a/templates/fungible-asset-template/scripts/move/upgrade.js b/templates/fungible-asset-template/scripts/move/upgrade.js index 716c6448..83b16171 100644 --- a/templates/fungible-asset-template/scripts/move/upgrade.js +++ b/templates/fungible-asset-template/scripts/move/upgrade.js @@ -27,7 +27,7 @@ async function publish() { // Please find it on the network you are using, This is testnet deployment minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490", }, - profile: process.env.VITE_APP_NETWORK, + profile: process.env.PROFILE_NAME, }); } publish();