From 76d2bf67bedf55243fccec6166de359a14a6fc69 Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Thu, 28 Sep 2023 18:54:59 +0300 Subject: [PATCH 1/3] Allow registration & setup of names in a single PTB --- packages/utils/Move.lock | 31 ++++++++++++++ packages/utils/Move.toml | 10 +++++ packages/utils/sources/direct_setup.move | 41 +++++++++++++++++++ scripts/config/constants.ts | 19 +++++---- .../transactions/authorize_direct_setup.ts | 34 +++++++++++++++ 5 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 packages/utils/Move.lock create mode 100644 packages/utils/Move.toml create mode 100644 packages/utils/sources/direct_setup.move create mode 100644 scripts/transactions/authorize_direct_setup.ts diff --git a/packages/utils/Move.lock b/packages/utils/Move.lock new file mode 100644 index 00000000..b3a58ca4 --- /dev/null +++ b/packages/utils/Move.lock @@ -0,0 +1,31 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 0 +manifest_digest = "EE479753CF869115F6C15EFFEE4A4F51363E4A07A23A076868DE76C8B3F887F3" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" + +dependencies = [ + { name = "Sui" }, + { name = "suins" }, +] + +[[move.package]] +name = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +name = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { name = "MoveStdlib" }, +] + +[[move.package]] +name = "suins" +source = { local = "../suins" } + +dependencies = [ + { name = "Sui" }, +] diff --git a/packages/utils/Move.toml b/packages/utils/Move.toml new file mode 100644 index 00000000..9d0e283a --- /dev/null +++ b/packages/utils/Move.toml @@ -0,0 +1,10 @@ +[package] +name = "utils" +version = "0.0.1" + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet", override=true } +suins = { local = "../suins" } + +[addresses] +utils = "0x0" diff --git a/packages/utils/sources/direct_setup.move b/packages/utils/sources/direct_setup.move new file mode 100644 index 00000000..88439d34 --- /dev/null +++ b/packages/utils/sources/direct_setup.move @@ -0,0 +1,41 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +/// A simple package to allows us set a target address & default name in a single PTB in frontend. +/// Unblocks better UX in the registration flow | easier adoption for non-technical users. +module utils::direct_setup { + use std::option; + use std::string::{String}; + + use sui::tx_context::{TxContext, sender}; + use sui::clock::Clock; + + use suins::domain; + use suins::registry::{Self, Registry}; + use suins::suins::{Self, SuiNS}; + use suins::suins_registration::{Self as nft, SuinsRegistration}; + + /// Authorization token for the controller. + struct DirectSetup has drop {} + + /// Set the target address of a domain. + public fun set_target_address( + suins: &mut SuiNS, + nft: &SuinsRegistration, + new_target: address, + clock: &Clock, + ) { + let registry = suins::app_registry_mut(DirectSetup {}, suins); + registry::assert_nft_is_authorized(registry, nft, clock); + + let domain = nft::domain(nft); + registry::set_target_address(registry, domain, option::some(new_target)); + } + + /// Set the reverse lookup address for the domain + public fun set_reverse_lookup(suins: &mut SuiNS, domain_name: String, ctx: &TxContext) { + let domain = domain::new(domain_name); + let registry = suins::app_registry_mut(DirectSetup {}, suins); + registry::set_reverse_lookup(registry, sender(ctx), domain); + } +} diff --git a/scripts/config/constants.ts b/scripts/config/constants.ts index 1e131d66..c5aa1f79 100644 --- a/scripts/config/constants.ts +++ b/scripts/config/constants.ts @@ -5,15 +5,16 @@ export type Network = 'mainnet' | 'testnet' export type Config = Record export type PackageInfo = { - packageId: ObjectId; + packageId: string; registrationPackageId: string; - upgradeCap?: ObjectId; - publisherId:ObjectId; + upgradeCap?: string; + publisherId: string; adminAddress: SuiAddress; provider: JsonRpcProvider; - adminCap: ObjectId; - suins: ObjectId; - displayObject?: ObjectId; + adminCap: string; + suins: string; + displayObject?: string; + directSetupPackageId: string; } export const mainPackage: Config = { @@ -28,7 +29,8 @@ export const mainPackage: Config = { displayObject: '0x866fbd8e51b6637c25f0e811ece9a85eb417f3987ecdfefb80f15d1192d72b4c', provider: new JsonRpcProvider(new Connection({ fullnode: 'https://suins-rpc.mainnet.sui.io' - })) + })), + directSetupPackageId: 'TODO: Fill this in' }, testnet: { @@ -40,7 +42,8 @@ export const mainPackage: Config = { suins: '0xedc672fadedee348108618da7555f771d4fec8d3331779a8411ff8184aded726', provider: new JsonRpcProvider(new Connection({ fullnode: 'https://suins-rpc.testnet.sui.io:443' - })) + })), + directSetupPackageId: '0x9af70a4cb6d7144e68fd972eef672a74c7fe41aa5c0bb67ba40d7d1ae87bfb19' } } diff --git a/scripts/transactions/authorize_direct_setup.ts b/scripts/transactions/authorize_direct_setup.ts new file mode 100644 index 00000000..339e85fa --- /dev/null +++ b/scripts/transactions/authorize_direct_setup.ts @@ -0,0 +1,34 @@ +// Copyright (c) 2023, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import dotenv from "dotenv"; +dotenv.config(); +import { executeTx, prepareMultisigTx, prepareSigner } from "../airdrop/helper"; +import { TransactionBlock } from "@mysten/sui.js"; +import { Network, mainPackage } from "../config/constants"; + +export const authorizeDirectSetupApp = async (network: Network) => { + const tx = new TransactionBlock(); + + const config = mainPackage[network]; + + // authorize the direct setup app. + tx.moveCall({ + target: `${config.packageId}::suins::authorize_app`, + arguments: [ + tx.object(config.adminCap), + tx.object(config.suins), + ], + typeArguments: [`${config.directSetupPackageId}::direct_setup::DirectSetup`], + }); + + // for mainnet, we just prepare multisig TX + if(network === 'mainnet') return prepareMultisigTx(tx, 'mainnet'); + + return executeTx(prepareSigner(config.provider), tx); + // prepare tx data. + +} + +authorizeDirectSetupApp("mainnet"); +// authorizeDirectSetupApp("testnet"); From 0287d313dbf1ff143625d26e847c66fe8e64a074 Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Wed, 4 Oct 2023 15:26:00 +0300 Subject: [PATCH 2/3] Prepare for multi-sig operations --- .github/workflows/suins-build-tx.yaml | 22 +++++++++++++++++ ...ize_direct_setup.ts => authorize_utils.ts} | 0 scripts/transactions/publish_utils.ts | 24 +++++++++++++++++++ 3 files changed, 46 insertions(+) rename scripts/transactions/{authorize_direct_setup.ts => authorize_utils.ts} (100%) create mode 100644 scripts/transactions/publish_utils.ts diff --git a/.github/workflows/suins-build-tx.yaml b/.github/workflows/suins-build-tx.yaml index 4a3088fb..ae88d9eb 100644 --- a/.github/workflows/suins-build-tx.yaml +++ b/.github/workflows/suins-build-tx.yaml @@ -8,6 +8,8 @@ on: description: 'select transaction type to create' type: choice options: + - Publish Utils + - Authorize Utils - Withdraw Auction Profits - Transfer Reserved Names - Main package upgrade @@ -113,6 +115,26 @@ jobs: run: | cd scripts && pnpm withdraw:auction:profits + - name: Publish Utils + if: ${{ inputs.transaction_type == 'Publish Utils' }} + env: + NODE_ENV: production + GAS_OBJECT: ${{ inputs.gas_object_id }} + NETWORK: mainnet + ORIGIN: gh_action + run: | + cd scripts && ts-node transactions/publish_utils.ts + + - name: Authorize Utils + if: ${{ inputs.transaction_type == 'Authorize Utils' }} + env: + NODE_ENV: production + GAS_OBJECT: ${{ inputs.gas_object_id }} + NETWORK: mainnet + ORIGIN: gh_action + run: | + cd scripts && ts-node transactions/authorize_utils.ts + - name: Show Transaction Data (To sign) run: | cat scripts/tx/tx-data.txt diff --git a/scripts/transactions/authorize_direct_setup.ts b/scripts/transactions/authorize_utils.ts similarity index 100% rename from scripts/transactions/authorize_direct_setup.ts rename to scripts/transactions/authorize_utils.ts diff --git a/scripts/transactions/publish_utils.ts b/scripts/transactions/publish_utils.ts new file mode 100644 index 00000000..ba4196f3 --- /dev/null +++ b/scripts/transactions/publish_utils.ts @@ -0,0 +1,24 @@ +// Copyright (c) 2023, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +import dotenv from "dotenv"; +dotenv.config(); +import { execSync } from 'child_process'; + +const gasObject = process.env.GAS_OBJECT; + +// Github actions are always on mainnet. +// This will publish the day_one package. +const publish = async () => { + + if(!gasObject) throw new Error("Gas Object not supplied for a mainnet transaction"); + + // on GH Action, the sui binary is located on root. Referencing that as `/` doesn't work. + const suiFolder = process.env.ORIGIN === 'gh_action' ? '../../sui' : 'sui'; + const publishCall = `${suiFolder} client publish --gas-budget 3000000000 --gas ${gasObject} --serialize-unsigned-transaction` + + // to suins/..(packages)/..(base)/scripts/tx/tx-data.txt + execSync(`cd $PWD/../packages/utils && ${publishCall} > $PWD/../../scripts/tx/tx-data.txt`); +} + +publish(); From fd52bc43dfd7a7d40618deb0eb55799efd4e4e70 Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Wed, 4 Oct 2023 15:30:10 +0300 Subject: [PATCH 3/3] Fix actions --- .github/workflows/suins-build-tx.yaml | 4 ++-- scripts/package.json | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/suins-build-tx.yaml b/.github/workflows/suins-build-tx.yaml index ae88d9eb..9b8c708d 100644 --- a/.github/workflows/suins-build-tx.yaml +++ b/.github/workflows/suins-build-tx.yaml @@ -123,7 +123,7 @@ jobs: NETWORK: mainnet ORIGIN: gh_action run: | - cd scripts && ts-node transactions/publish_utils.ts + cd scripts && pnpm publish-utils - name: Authorize Utils if: ${{ inputs.transaction_type == 'Authorize Utils' }} @@ -133,7 +133,7 @@ jobs: NETWORK: mainnet ORIGIN: gh_action run: | - cd scripts && ts-node transactions/authorize_utils.ts + cd scripts && pnpm authorize-utils - name: Show Transaction Data (To sign) run: | diff --git a/scripts/package.json b/scripts/package.json index a6427534..de252668 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -9,7 +9,9 @@ "migrations::day_one::deauthorize": "ts-node transactions/deauthorize_bogo_app.ts", "transactions::registration::publish": "ts-node transactions/publish_registration.ts", "transfer::names": "ts-node reserved-names/transfer-names.ts", - "withdraw:auction:profits":"ts-node transactions/withdraw_funds_20290927.ts" + "withdraw:auction:profits":"ts-node transactions/withdraw_funds_20290927.ts", + "publish-utils": "ts-node transactions/publish_utils.ts", + "authorize-utils": "ts-node transactions/authorize_utils.ts" }, "keywords": [], "author": "",