-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1/N] Adds scripts to setup SuiNS from scratch (#83)
[1/N] Adds scripts to spin up SuiNS in any network from scratch
- Loading branch information
1 parent
e563404
commit 726570d
Showing
19 changed files
with
714 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ sui.log.* | |
node_modules | ||
tx-data.txt* | ||
.DS_STORE* | ||
published.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}" | ||
`; |
Oops, something went wrong.