From d172868c6ddfa0fb0f1282fbe704d79195e9bd16 Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Mon, 2 Oct 2023 12:02:57 +0300 Subject: [PATCH 1/2] Quest 3 setup scripts --- packages/day_one/Move.toml | 5 +- packages/day_one/README.md | 10 ++ scripts/config/constants.ts | 14 ++- scripts/transactions/publish_coupons.ts | 22 +++++ scripts/transactions/publish_discounts.ts | 22 +++++ scripts/transactions/quest_3_setup.ts | 109 ++++++++++++++++++++++ scripts/tsconfig.json | 2 +- 7 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 scripts/transactions/publish_coupons.ts create mode 100644 scripts/transactions/publish_discounts.ts create mode 100644 scripts/transactions/quest_3_setup.ts diff --git a/packages/day_one/Move.toml b/packages/day_one/Move.toml index 6deb09f5..d91662dc 100644 --- a/packages/day_one/Move.toml +++ b/packages/day_one/Move.toml @@ -1,11 +1,12 @@ [package] name = "day_one" version = "0.0.1" +published-at="0xbf1431324a4a6eadd70e0ac6c5a16f36492f255ed4d011978b2cf34ad738efe6" [dependencies] -Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "2d985a3" } +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" } suins = { local = "../suins" } [addresses] -day_one = "0x0" +day_one = "0xbf1431324a4a6eadd70e0ac6c5a16f36492f255ed4d011978b2cf34ad738efe6" diff --git a/packages/day_one/README.md b/packages/day_one/README.md index 8a4435c9..25d07560 100644 --- a/packages/day_one/README.md +++ b/packages/day_one/README.md @@ -5,3 +5,13 @@ We will have new promotions that will depend on the `DayOne` struct, but it will only be useful as long as users have activated it. The DayOne can only be activated by the `bogo` module, which is the first promotion run for DayOne holders. + + +## Mainnet + +V1: `0xbf1431324a4a6eadd70e0ac6c5a16f36492f255ed4d011978b2cf34ad738efe6` + +## Testnet + + +V1: `0x7bd306e890d403f52d89e860a3c21a8c5717e64f954103b3023cafa31179e60c` diff --git a/scripts/config/constants.ts b/scripts/config/constants.ts index e7800a38..4c55b838 100644 --- a/scripts/config/constants.ts +++ b/scripts/config/constants.ts @@ -15,6 +15,10 @@ export type PackageInfo = { suins: string; displayObject?: string; directSetupPackageId: string; + discountsPackage: { + packageId: string; + discountHouseId: string; + } } export const mainPackage: Config = { @@ -30,6 +34,10 @@ export const mainPackage: Config = { provider: new JsonRpcProvider(new Connection({ fullnode: 'https://suins-rpc.mainnet.sui.io' })), + discountsPackage: { + packageId: '', + discountHouseId: '', + },, directSetupPackageId: '0xdac22652eb400beb1f5e2126459cae8eedc116b73b8ad60b71e3e8d7fdb317e2' }, @@ -43,7 +51,11 @@ export const mainPackage: Config = { provider: new JsonRpcProvider(new Connection({ fullnode: 'https://suins-rpc.testnet.sui.io:443' })), - directSetupPackageId: '0x9af70a4cb6d7144e68fd972eef672a74c7fe41aa5c0bb67ba40d7d1ae87bfb19' + directSetupPackageId: '0x9af70a4cb6d7144e68fd972eef672a74c7fe41aa5c0bb67ba40d7d1ae87bfb19', + discountsPackage: { + packageId: '0xa784ba6d2a3e7f0a51f332ce0cbb147e72b09b03ed56e96024178c538f9ff0ab', + discountHouseId: '0x599385bf98d823368069df46143ce9906aa4dec8beedfe8f560fcceb2b5580e5', + }, } } diff --git a/scripts/transactions/publish_coupons.ts b/scripts/transactions/publish_coupons.ts new file mode 100644 index 00000000..61b98960 --- /dev/null +++ b/scripts/transactions/publish_coupons.ts @@ -0,0 +1,22 @@ +// 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; + +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/coupons && ${publishCall} > $PWD/../../scripts/tx/tx-data.txt`); +} + +publish(); diff --git a/scripts/transactions/publish_discounts.ts b/scripts/transactions/publish_discounts.ts new file mode 100644 index 00000000..2bed581c --- /dev/null +++ b/scripts/transactions/publish_discounts.ts @@ -0,0 +1,22 @@ +// 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; + +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/discounts && ${publishCall} > $PWD/../../scripts/tx/tx-data.txt`); +} + +publish(); diff --git a/scripts/transactions/quest_3_setup.ts b/scripts/transactions/quest_3_setup.ts new file mode 100644 index 00000000..a85e9193 --- /dev/null +++ b/scripts/transactions/quest_3_setup.ts @@ -0,0 +1,109 @@ +// 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 { Network, PackageInfo, mainPackage } from "../config/constants"; +import { MIST_PER_SUI, TransactionBlock } from "@mysten/sui.js"; + +const SUIFREN_BULLSHARK_TYPE: Record = { + mainnet: '0xee496a0cc04d06a345982ba6697c90c619020de9e274408c7819f787ff66e1a1::suifrens::SuiFren<0x8894fa02fc6f36cbc485ae9145d05f247a78e220814fb8419ab261bd81f08f32::bullshark::Bullshark>', + testnet: '0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::suifrens::SuiFren<0x297d8afb6ede450529d347cf9254caeea2b685c8baef67b084122291ebaefb38::bullshark::Bullshark>' +}; + +const SUIFREN_CAPY_TYPE: Record = { + mainnet: '0xee496a0cc04d06a345982ba6697c90c619020de9e274408c7819f787ff66e1a1::suifrens::SuiFren<0xee496a0cc04d06a345982ba6697c90c619020de9e274408c7819f787ff66e1a1::capy::Capy>', + testnet: '0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::suifrens::SuiFren<0x80d7de9c4a56194087e0ba0bf59492aa8e6a5ee881606226930827085ddf2332::capy::Capy>' +}; + +const DAY_ONE_TYPE: Record = { + mainnet: '0xbf1431324a4a6eadd70e0ac6c5a16f36492f255ed4d011978b2cf34ad738efe6::day_one::DayOne', + testnet: '0x71c2dc2ce8a3cde0f7fa6638519c64f24b1b7bc20e8272d2ca0690ffbbfabc4a::day_one::DayOne' +}; + +// Discount setup. (Final pricing) +export type Discount = { + threeCharacterPrice: bigint; + fourCharacterPrice: bigint; + fivePlusCharacterPrice: bigint; +} +// A char range available for free claims. +export type Range = { + from: number; + to: number; +} + +// Sets up discount prices for type. +const setupDiscountForType = (txb: TransactionBlock, setup: PackageInfo, type: string, prices: Discount) => { + txb.moveCall({ + target: `${setup.discountsPackage.packageId}::discounts::authorize_type`, + arguments: [ + txb.object(setup.adminCap), + txb.object(setup.discountsPackage.discountHouseId), + txb.pure(prices.threeCharacterPrice, 'u64'), + txb.pure(prices.fourCharacterPrice, 'u64'), + txb.pure(prices.fivePlusCharacterPrice, 'u64'), + ], + typeArguments: [type] + }); +} + +// Sets up free claims for type. +const setupFreeClaimsForType = (txb: TransactionBlock, setup: PackageInfo, type: string, characters: Range) => { + txb.moveCall({ + target: `${setup.discountsPackage.packageId}::free_claims::authorize_type`, + arguments: [ + txb.object(setup.adminCap), + txb.object(setup.discountsPackage.discountHouseId), + txb.pure([characters.from, characters.to], 'vector') + ], + typeArguments: [type] + }); +} + +// Setup Quests 3. +const setup = async (network: Network) => { + const setup = mainPackage[network]; + + const txb = new TransactionBlock(); + + // authorize `discount` package to claim names + txb.moveCall({ + target: `${setup.packageId}::suins::authorize_app`, + arguments: [ + txb.object(setup.adminCap), + txb.object(setup.suins), + ], + typeArguments: [`${setup.discountsPackage.packageId}::house::DiscountHouseApp`], + }); + + // setup `discount` both for free-claims & discounts by presenting type. + // 3 chars -> 250 | 4 chars -> 50 | 5 chars+ -> 10 + const priceList: Discount = { + threeCharacterPrice: 250n * MIST_PER_SUI, + fourCharacterPrice: 50n * MIST_PER_SUI, + fivePlusCharacterPrice: 10n * MIST_PER_SUI + }; + + /// authorize the discounts package to allow name registrations. + setupDiscountForType(txb, setup, SUIFREN_BULLSHARK_TYPE[network], priceList); + setupDiscountForType(txb, setup, SUIFREN_CAPY_TYPE[network], priceList); + setupDiscountForType(txb, setup, DAY_ONE_TYPE[network], priceList); + + // authorize the free claims to allow free claiming for 10+ names. + setupFreeClaimsForType(txb, setup, SUIFREN_BULLSHARK_TYPE[network], { from: 10, to: 63 }); + setupFreeClaimsForType(txb, setup, SUIFREN_CAPY_TYPE[network], { from: 10, to: 63 }); + setupFreeClaimsForType(txb, setup, DAY_ONE_TYPE[network], { from: 10, to: 63 }); + + // for mainnet, we prepare the multi-sig tx. + if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); + + // For testnet, we execute the TX directly. + return executeTx(prepareSigner(setup.provider), txb); +} + +if(process.env.NETWORK === 'mainnet') setup('mainnet') +else setup('testnet'); + + diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index e075f973..34668965 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ From 1f23bd28ed6300980904186e5cf030664ee4d32c Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Wed, 11 Oct 2023 12:10:50 -0700 Subject: [PATCH 2/2] Finalize flows for quests 3 authorization --- .github/workflows/suins-build-tx.yaml | 16 ++++++++-------- packages/day_one/Move.toml | 2 +- packages/discounts/Move.lock | 6 +++--- packages/discounts/Move.toml | 2 +- packages/discounts/sources/discounts.move | 4 +++- packages/discounts/tests/discount_tests.move | 6 +++--- scripts/config/constants.ts | 6 +++--- scripts/package.json | 4 +++- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.github/workflows/suins-build-tx.yaml b/.github/workflows/suins-build-tx.yaml index 9b8c708d..ef0df2e5 100644 --- a/.github/workflows/suins-build-tx.yaml +++ b/.github/workflows/suins-build-tx.yaml @@ -8,8 +8,8 @@ on: description: 'select transaction type to create' type: choice options: - - Publish Utils - - Authorize Utils + - Publish Discounts + - Authorize Discounts - Withdraw Auction Profits - Transfer Reserved Names - Main package upgrade @@ -115,25 +115,25 @@ jobs: run: | cd scripts && pnpm withdraw:auction:profits - - name: Publish Utils - if: ${{ inputs.transaction_type == 'Publish Utils' }} + - name: Publish Discounts + if: ${{ inputs.transaction_type == 'Publish Discounts' }} env: NODE_ENV: production GAS_OBJECT: ${{ inputs.gas_object_id }} NETWORK: mainnet ORIGIN: gh_action run: | - cd scripts && pnpm publish-utils + cd scripts && pnpm publish-discounts - - name: Authorize Utils - if: ${{ inputs.transaction_type == 'Authorize Utils' }} + - name: Authorize Discounts + if: ${{ inputs.transaction_type == 'Authorize Discounts' }} env: NODE_ENV: production GAS_OBJECT: ${{ inputs.gas_object_id }} NETWORK: mainnet ORIGIN: gh_action run: | - cd scripts && pnpm authorize-utils + cd scripts && pnpm authorize-discounts - name: Show Transaction Data (To sign) run: | diff --git a/packages/day_one/Move.toml b/packages/day_one/Move.toml index d91662dc..0757228a 100644 --- a/packages/day_one/Move.toml +++ b/packages/day_one/Move.toml @@ -4,7 +4,7 @@ version = "0.0.1" published-at="0xbf1431324a4a6eadd70e0ac6c5a16f36492f255ed4d011978b2cf34ad738efe6" [dependencies] -Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" } +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "2d985a3" } suins = { local = "../suins" } diff --git a/packages/discounts/Move.lock b/packages/discounts/Move.lock index 136ae810..200def0f 100644 --- a/packages/discounts/Move.lock +++ b/packages/discounts/Move.lock @@ -2,7 +2,7 @@ [move] version = 0 -manifest_digest = "87F5FF1A0FA485D7D0BCCB2C91C7735B8B019AE73BA311049CEED5DDBEF1E16A" +manifest_digest = "3AED8A6ABDB452446388F627000D349F8CCC747A20B6A81510D9A94CD9782C8A" deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" dependencies = [ @@ -13,11 +13,11 @@ dependencies = [ [[move.package]] name = "MoveStdlib" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } [[move.package]] name = "Sui" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" } dependencies = [ { name = "MoveStdlib" }, diff --git a/packages/discounts/Move.toml b/packages/discounts/Move.toml index b441b69e..74a113d5 100644 --- a/packages/discounts/Move.toml +++ b/packages/discounts/Move.toml @@ -3,7 +3,7 @@ name = "discounts" version = "0.0.1" [dependencies] -Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet", override=true } +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet", override=true } suins = { local = "../suins" } day_one = { local = "../day_one" } diff --git a/packages/discounts/sources/discounts.move b/packages/discounts/sources/discounts.move index 0cf3216b..014dd889 100644 --- a/packages/discounts/sources/discounts.move +++ b/packages/discounts/sources/discounts.move @@ -8,7 +8,7 @@ /// Can be called only when promotions are active for a specific type T. /// Activation / deactivation happens through PTBs. module discounts::discounts { - + use std::option::{Option}; use std::string::{Self, String}; use std::type_name::{Self as type}; @@ -57,6 +57,7 @@ module discounts::discounts { domain_name: String, payment: Coin, clock: &Clock, + _reseller: Option, ctx: &mut TxContext ): SuinsRegistration { // For normal flow, we do not allow DayOne to be used. @@ -75,6 +76,7 @@ module discounts::discounts { domain_name: String, payment: Coin, clock: &Clock, + _reseller: Option, ctx: &mut TxContext ): SuinsRegistration { assert!(is_active(day_one), ENotActiveDayOne); diff --git a/packages/discounts/tests/discount_tests.move b/packages/discounts/tests/discount_tests.move index f88a3929..8d4ad025 100644 --- a/packages/discounts/tests/discount_tests.move +++ b/packages/discounts/tests/discount_tests.move @@ -3,7 +3,7 @@ #[test_only] module discounts::discount_tests { - + use std::option; use std::string::{utf8, String}; use sui::test_scenario::{Self as ts, Scenario, ctx}; @@ -78,7 +78,7 @@ module discounts::discount_tests { let discount_house = ts::take_shared(scenario); let clock = ts::take_shared(scenario); - let name = discounts::register(&mut discount_house, &mut suins, item, domain_name, payment, &clock, ctx(scenario)); + let name = discounts::register(&mut discount_house, &mut suins, item, domain_name, payment, &clock, option::none(), ctx(scenario)); transfer::public_transfer(name, user); @@ -99,7 +99,7 @@ module discounts::discount_tests { let discount_house = ts::take_shared(scenario); let clock = ts::take_shared(scenario); - let name = discounts::register_with_day_one(&mut discount_house, &mut suins, item, domain_name, payment, &clock, ctx(scenario)); + let name = discounts::register_with_day_one(&mut discount_house, &mut suins, item, domain_name, payment, &clock, option::none(), ctx(scenario)); transfer::public_transfer(name, user); diff --git a/scripts/config/constants.ts b/scripts/config/constants.ts index 4c55b838..16be4b62 100644 --- a/scripts/config/constants.ts +++ b/scripts/config/constants.ts @@ -35,9 +35,9 @@ export const mainPackage: Config = { fullnode: 'https://suins-rpc.mainnet.sui.io' })), discountsPackage: { - packageId: '', - discountHouseId: '', - },, + packageId: 'TODO: FILL THIS IN', + discountHouseId: 'TODO: Fill this in', + }, directSetupPackageId: '0xdac22652eb400beb1f5e2126459cae8eedc116b73b8ad60b71e3e8d7fdb317e2' }, diff --git a/scripts/package.json b/scripts/package.json index de252668..98fa3242 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -11,7 +11,9 @@ "transfer::names": "ts-node reserved-names/transfer-names.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" + "authorize-utils": "ts-node transactions/authorize_utils.ts", + "publish-discounts": "ts-node transactions/publish_discounts.ts", + "authorize-discounts": "ts-node transactions/quest_3_setup.ts" }, "keywords": [], "author": "",