Skip to content

Commit

Permalink
Merge pull request #26 from MystenLabs/ml/single-ptb-registry-setup
Browse files Browse the repository at this point in the history
Allow registration & setup of names in a single PTB
  • Loading branch information
manolisliolios authored Oct 4, 2023
2 parents fb955c3 + fd52bc4 commit bea36a2
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 9 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/suins-build-tx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 && pnpm publish-utils
- 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 && pnpm authorize-utils
- name: Show Transaction Data (To sign)
run: |
cat scripts/tx/tx-data.txt
Expand Down
31 changes: 31 additions & 0 deletions packages/utils/Move.lock
Original file line number Diff line number Diff line change
@@ -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" },
]
10 changes: 10 additions & 0 deletions packages/utils/Move.toml
Original file line number Diff line number Diff line change
@@ -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"
41 changes: 41 additions & 0 deletions packages/utils/sources/direct_setup.move
Original file line number Diff line number Diff line change
@@ -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, Registry>(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, Registry>(DirectSetup {}, suins);
registry::set_reverse_lookup(registry, sender(ctx), domain);
}
}
19 changes: 11 additions & 8 deletions scripts/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ export type Network = 'mainnet' | 'testnet'
export type Config = Record<Network, PackageInfo>

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 = {
Expand All @@ -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: {
Expand All @@ -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'
}
}

Expand Down
4 changes: 3 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
34 changes: 34 additions & 0 deletions scripts/transactions/authorize_utils.ts
Original file line number Diff line number Diff line change
@@ -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");
24 changes: 24 additions & 0 deletions scripts/transactions/publish_utils.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit bea36a2

Please sign in to comment.