Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds scripts to setup SuiNS from scratch #83

Merged
merged 9 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/suins-build-tx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ on:
description: 'select transaction type to create'
type: choice
options:
- Authorize Basecamp Free Claim
- Disable Discounts
- Disable Free Claims
- Withdraw Auction Profits
- Profits to Treasury
- Transfer Reserved Names
- Main package upgrade
- Create Deepbook Pools
sui_tools_image:
description: 'image reference of sui_tools'
default: 'mysten/sui-tools:mainnet'
Expand Down Expand Up @@ -107,15 +105,15 @@ jobs:
run: |
cd scripts && pnpm transfer::names

- name: Withdraw Auction Profits
if: ${{ inputs.transaction_type == 'Withdraw Auction Profits' }}
- name: Profits to Treasury
if: ${{ inputs.transaction_type == 'Profits to Treasury' }}
env:
NODE_ENV: production
GAS_OBJECT: ${{ inputs.gas_object_id }}
NETWORK: mainnet
ORIGIN: gh_action
run: |
cd scripts && pnpm withdraw:auction:profits
cd scripts && pnpm withdraw:profits

- name: Authorize Basecamp Free Claim
if: ${{ inputs.transaction_type == 'Authorize Basecamp Free Claim' }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ sui.log.*
node_modules
tx-data.txt*
.DS_STORE*
published.json
2 changes: 1 addition & 1 deletion packages/renewal/sources/renew.move
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module renewal::renew {
/// and we can only have 1 config of each type in the suins app.
/// We still set this up by using the default config functionality from suins package.
/// The `public_key` passed in the `Config` can be a random u8 array with length 33.
public fun setup(cap: &AdminCap, suins: &mut SuiNS, config: Config) {
public fun setup(suins: &mut SuiNS, cap: &AdminCap, config: Config) {
suins::add_config<RenewalConfig>(cap, suins, RenewalConfig { config });
}

Expand Down
2 changes: 1 addition & 1 deletion packages/renewal/tests/renew_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module renewal::renew_tests {
REGULAR_PRICE * ::suins::constants::mist_per_sui(),
);

renewal::setup(&cap, &mut suins, config);
renewal::setup(&mut suins, &cap, config);

let nft = registry.add_record(domain, 1,&clock, ctx);
suins::add_registry(&cap, &mut suins, registry);
Expand Down
22 changes: 22 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Scripts

This directory contains different scripts used to build transactions (for multi-sig operations).



## Setup SuiNS locally

To setup a local instance of SuiNS (or in any network of your choosing), all you need to do is call:

```
# choose from mainnet, testnet, devnet, localnet
export NETWORK=localnet
pnpm ts-node init/init.ts
```

This will automatically publish all the packages in the correct order, collect all the variables in a `published.json`
file, as well as do a full on-chain setup (creation of the registry, addition of pricelist, authorizing all apps).

Then, you can use these published variables to the SDK and call different actions (e.g. registering names, subnames etc)

> Do not check-in the `Move.lock` and `Move.toml` changes if you are submitting a PR.
2 changes: 1 addition & 1 deletion scripts/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { normalizeSuiAddress } from "@mysten/sui.js/utils";

export type Network = 'mainnet' | 'testnet'

export type Config = Record<Network, PackageInfo>
export type Config = Record<'mainnet' | 'testnet', PackageInfo>

export type PackageInfo = {
packageId: string;
Expand Down
159 changes: 159 additions & 0 deletions scripts/init/authorization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { TransactionArgument, TransactionBlock } from "@mysten/sui.js/transactions";

/**
* A helper to authorize any app in the SuiNS object.
*/
export const authorizeApp = ({
txb, adminCap, suins, type, suinsPackageIdV1
}: {
txb: TransactionBlock;
adminCap: string;
suins: string;
type: string;
suinsPackageIdV1: string;
}) => {
console.log({adminCap, suins, type, suinsPackageIdV1})
txb.moveCall({
target: `${suinsPackageIdV1}::suins::authorize_app`,
arguments: [
txb.object(adminCap),
txb.object(suins),
],
typeArguments: [type],
});
}

/**
* A helper to deauthorize any app that has been authorized on the SuiNS object.
*/
export const deauthorizeApp = ({
txb, adminCap, suins, type, suinsPackageIdV1
}: {
txb: TransactionBlock;
adminCap: string;
suins: string;
type: string;
suinsPackageIdV1: string;
}
) => {
txb.moveCall({
target: `${suinsPackageIdV1}::suins::deauthorize_app`,
arguments: [
txb.object(adminCap),
txb.object(suins),
],
typeArguments: [type],
});
}

/**
* A helper to call `setup` function for many apps that create a "registry" to hold state.
*/
export const setupApp = ({
txb, adminCap, suins, target, args
}: {
txb: TransactionBlock;
adminCap: string;
suins: string;
target: `${string}::${string}`,
args?: TransactionArgument[];
}
) => {
txb.moveCall({
target: `${target}::setup`,
arguments: [
txb.object(suins),
txb.object(adminCap),
...(args || [])
],
});
}

/**
* Add a config to the SuiNS object.
*/
export const addConfig = ({
txb, adminCap, suins, type, config, suinsPackageIdV1
}: {
txb: TransactionBlock;
adminCap: string;
suins: string;
suinsPackageIdV1: string;
config: TransactionArgument;
type: string;
}) => {
txb.moveCall({
target: `${suinsPackageIdV1}::suins::add_config`,
arguments: [
txb.object(adminCap),
txb.object(suins),
config
],
typeArguments: [type]
});
}

/**
* Creates a default `config` which saves the price list and public key.
*/
export const newPriceConfig = ({
txb, suinsPackageIdV1, priceList, publicKey = [...Array(33).keys()]
}: {
txb: TransactionBlock;
suinsPackageIdV1: string;
priceList: { [key: string]: number };
publicKey?: number[];

}): TransactionArgument => {
return txb.moveCall({
target: `${suinsPackageIdV1}::config::new`,
arguments: [
txb.pure(publicKey),
txb.pure(priceList.three),
txb.pure(priceList.four),
txb.pure(priceList.fivePlus),
],
});

}

/**
* Add a registry to the SuiNS object.
*/
export const addRegistry = ({
txb, adminCap, suins, type, registry, suinsPackageIdV1
}: {
txb: TransactionBlock;
adminCap: string;
suins: string;
suinsPackageIdV1: string;
registry: TransactionArgument;
type: string;
}) => {
txb.moveCall({
target: `${suinsPackageIdV1}::suins::add_registry`,
arguments: [
txb.object(adminCap),
txb.object(suins),
registry
],
typeArguments: [type]
});
}

/**
* Creates a default `registry` which saves direct/reverse lookups.
* That serves as the main registry for the SuiNS object after adding it.
*/
export const newLookupRegistry = ({
txb, adminCap, suinsPackageIdV1
}: {
txb: TransactionBlock;
adminCap: string;
suinsPackageIdV1: string;
}): TransactionArgument => {
return txb.moveCall({
target: `${suinsPackageIdV1}::registry::new`,
arguments: [txb.object(adminCap)],
});
}
55 changes: 55 additions & 0 deletions scripts/init/display_tp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { TransactionBlock } from "@mysten/sui.js/transactions";

/** Creates the display. Should be called for both subnames and names. */
export const createDisplay = ({
txb, publisher, isSubdomain, suinsPackageIdV1
}: {
txb: TransactionBlock;
publisher: string;
isSubdomain: boolean;
suinsPackageIdV1: string;
}) => {

const display = txb.moveCall({
target: `0x2::display::new`,
arguments: [txb.object(publisher)],
typeArguments: [
isSubdomain ? `${suinsPackageIdV1}::subdomain_registration::SubDomainRegistration` :
`${suinsPackageIdV1}::suins_registration::SuinsRegistration`,
],
});

txb.moveCall({
target: `0x2::display::add_multiple`,
arguments: [
display,
txb.pure(['name', 'link', 'image_url', 'description', 'project_url']),
txb.pure([
`{${isSubdomain ? 'nft.' : ''}domain_name}`,
`https://{${isSubdomain ? 'nft.' : ''}domain_name}.id`,
`https://storage.googleapis.com/suins-nft-images/{${isSubdomain ? 'nft.' : ''}image_url}.png`,
'SuiNS - Sculpt Your Identity',
'https://suins.io',
]),
],
typeArguments: [
isSubdomain ? `${suinsPackageIdV1}::subdomain_registration::SubDomainRegistration` :
`${suinsPackageIdV1}::suins_registration::SuinsRegistration`,
],
});

txb.moveCall({
target: `0x2::display::update_version`,
arguments: [display],
typeArguments: [
isSubdomain ? `${suinsPackageIdV1}::subdomain_registration::SubDomainRegistration` :
`${suinsPackageIdV1}::suins_registration::SuinsRegistration`,
],
});

const sender = txb.moveCall({
target: '0x2::tx_context::sender'
});

txb.transferObjects([display], sender);
}
10 changes: 10 additions & 0 deletions scripts/init/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Network } from "./packages";
import { publishPackages } from "./publish"
import { setup } from "./setup";

export const init = async (network: Network) => {
const published = await publishPackages(network);
await setup(published, network);
}

init(process.env.NETWORK as Network);
40 changes: 40 additions & 0 deletions scripts/init/manifests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const SuiNS = (rev: string) => (packageId?: string) => `[package]
name = "suins"
version = "0.0.1"
edition = "2024.beta"
${packageId ? `published-at = "${packageId}"`: ''}

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "${rev}" }

[addresses]
suins = "${packageId || '0x0'}"`;

export const SuiNSDependentPackages = (rev: string, name: string, extraDependencies?: string) => (packageId?: string) => `[package]
name = "${name}"
version = "0.0.1"
edition = "2024.beta"
${packageId ? `published-at = "${packageId}"`: ''}

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "${rev}", override=true }
suins = { local = "../suins" }
${extraDependencies || ''}

[addresses]
${name} = "${packageId || '0x0'}"`;

export const TempSubdomainProxy = (rev: string) => (packageId?: string) => `[package]
name = "temp_subdomain_proxy"
version = "0.0.1"
edition = "2024.beta"
${packageId ? `published-at = "${packageId}"`: ''}

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "${rev}", override=true }
subdomains = { local = "../subdomains" }
utils = { local = "../utils" }

[addresses]
temp_subdomain_proxy = "${packageId || '0x0'}"
`;
Loading
Loading