From 2718d6a835c6019b6d6e8272b839eb57cbd03e74 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Wed, 20 Mar 2024 10:06:48 -0400 Subject: [PATCH 01/14] use pyth oracle for price calc --- packages/registration/Move.lock | 25 ++++ packages/registration/Move.toml | 1 + packages/registration/sources/register.move | 32 ++++- .../registration/tests/register_tests.move | 133 +++++++++++++++--- 4 files changed, 170 insertions(+), 21 deletions(-) diff --git a/packages/registration/Move.lock b/packages/registration/Move.lock index a88ee9e2..3a5a45ac 100644 --- a/packages/registration/Move.lock +++ b/packages/registration/Move.lock @@ -2,8 +2,11 @@ [move] version = 0 +manifest_digest = "DF2D74504CBEBCC7EA362C169FB1A933D93EC1CE6FA96ACB465E13FE39349F72" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" dependencies = [ + { name = "Pyth" }, { name = "Sui" }, { name = "suins" }, ] @@ -12,6 +15,15 @@ dependencies = [ name = "MoveStdlib" source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } +[[move.package]] +name = "Pyth" +source = { git = "https://github.com/pyth-network/pyth-crosschain.git", rev = "sui-contract-v0.0.2-mainnet-sui-1.19.1", subdir = "target_chains/sui/contracts" } + +dependencies = [ + { name = "Sui" }, + { name = "Wormhole" }, +] + [[move.package]] name = "Sui" source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } @@ -20,6 +32,14 @@ dependencies = [ { name = "MoveStdlib" }, ] +[[move.package]] +name = "Wormhole" +source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "sui-upgrade-mainnet", subdir = "sui/wormhole" } + +dependencies = [ + { name = "Sui" }, +] + [[move.package]] name = "suins" source = { local = "../suins" } @@ -27,3 +47,8 @@ source = { local = "../suins" } dependencies = [ { name = "Sui" }, ] + +[move.toolchain-version] +compiler-version = "1.19.0" +edition = "legacy" +flavor = "sui" diff --git a/packages/registration/Move.toml b/packages/registration/Move.toml index 628138c6..9386aa03 100644 --- a/packages/registration/Move.toml +++ b/packages/registration/Move.toml @@ -5,6 +5,7 @@ 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" } +Pyth = {git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/sui/contracts", rev = "sui-contract-v0.0.2-mainnet-sui-1.19.1"} [addresses] registration = "0x0" diff --git a/packages/registration/sources/register.move b/packages/registration/sources/register.move index e57d08cb..2ce8506c 100644 --- a/packages/registration/sources/register.move +++ b/packages/registration/sources/register.move @@ -4,6 +4,7 @@ module registration::register { use std::string::{Self, String}; use sui::coin::{Self, Coin}; + use sui::math; use sui::tx_context::TxContext; use sui::clock::Clock; use sui::sui::SUI; @@ -14,6 +15,10 @@ module registration::register { use suins::config::{Self, Config}; use suins::suins_registration::SuinsRegistration; + use pyth::price_feed::{Self, PriceFeed}; + use pyth::price; + use pyth::i64; + /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; /// Trying to register a subdomain (only *.sui is currently allowed). @@ -35,6 +40,7 @@ module registration::register { domain_name: String, no_years: u8, payment: Coin, + price_feed: &PriceFeed, clock: &Clock, ctx: &mut TxContext ): SuinsRegistration { @@ -48,12 +54,34 @@ module registration::register { assert!(0 < no_years && no_years <= 5, EInvalidYearsArgument); let label = domain::sld(&domain); - let price = config::calculate_price(config, (string::length(label) as u8), no_years); - assert!(coin::value(&payment) == price, EIncorrectAmount); + let (sui_value_in_usd_lower_bound, sui_value_in_usd_upper_bound) = calculate_lower_upper_price(price_feed, coin::value(&payment)); + let price_in_usd = config::calculate_price(config, (string::length(label) as u8), no_years); + + assert!(sui_value_in_usd_lower_bound <= price_in_usd, EIncorrectAmount); + assert!(sui_value_in_usd_upper_bound >= price_in_usd, EIncorrectAmount); suins::app_add_balance(Register {}, suins, coin::into_balance(payment)); let registry = suins::app_registry_mut(Register {}, suins); registry::add_record(registry, domain, no_years, clock, ctx) } + + fun calculate_lower_upper_price( + price_feed: &PriceFeed, + sui_quantity: u64 + ): (u64, u64) { + // https://docs.pyth.network/price-feeds/pythnet-price-feeds/best-practices + let sui_price = &price_feed::get_price(price_feed); + let sui_price_i64 = &price::get_price(sui_price); + let sui_price_u64 = i64::get_magnitude_if_positive(sui_price_i64); + let sui_price_lower_bound = sui_price_u64 - price::get_conf(sui_price); + let sui_price_upper_bound = sui_price_u64 + price::get_conf(sui_price); + let exponent_i64 = &price::get_expo(sui_price); + let exponent_u8 = (i64::get_magnitude_if_negative(exponent_i64) as u8); + + let sui_value_in_usd_lower_bound = sui_quantity * sui_price_lower_bound / (math::pow(10, exponent_u8)); + let sui_value_in_usd_upper_bound = sui_quantity * sui_price_upper_bound / (math::pow(10, exponent_u8)); + + (sui_value_in_usd_lower_bound, sui_value_in_usd_upper_bound) + } } diff --git a/packages/registration/tests/register_tests.move b/packages/registration/tests/register_tests.move index cd383c5e..192a8ad3 100644 --- a/packages/registration/tests/register_tests.move +++ b/packages/registration/tests/register_tests.move @@ -22,6 +22,11 @@ module registration::register_tests { use suins::auction_tests; use suins::auction::{Self, App as AuctionApp}; + use pyth::price_identifier; + use pyth::price_feed::{Self, PriceFeed}; + use pyth::price; + use pyth::i64; + const SUINS_ADDRESS: address = @0xA001; const AUCTIONED_DOMAIN_NAME: vector = b"tes-t2.sui"; const DOMAIN_NAME: vector = b"abc.sui"; @@ -50,11 +55,23 @@ module registration::register_tests { scenario_val } + public fun oracle_util( + desired_price_6_decimals: u64 + ): PriceFeed { + let price_identifier = price_identifier::from_byte_vec(x"ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"); + let price_i64 = i64::new(desired_price_6_decimals, false); // ie: 1.610000 + let expo_i64 = i64::new(6, true); // 10^-6 + let price = price::new(price_i64, 10000, expo_i64, 0); // confidence is 1 cent + let ema_price = copy(price); + price_feed::new(price_identifier, price, ema_price) + } + public fun register_util( scenario: &mut Scenario, domain_name: String, no_years: u8, amount: u64, + price_feed: &PriceFeed, clock_tick: u64 ): SuinsRegistration { test_scenario::next_tx(scenario, SUINS_ADDRESS); @@ -63,7 +80,7 @@ module registration::register_tests { let clock = test_scenario::take_shared(scenario); clock::increment_for_testing(&mut clock, clock_tick); - let nft = register(&mut suins, domain_name, no_years, payment, &clock, ctx(scenario)); + let nft = register(&mut suins, domain_name, no_years, payment, price_feed, &clock, ctx(scenario)); test_scenario::return_shared(clock); test_scenario::return_shared(suins); @@ -93,20 +110,21 @@ module registration::register_tests { fun test_register() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); // $1 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), 20); + let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), &price_feed, 20); assert_balance(scenario, 1600 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), 30); + let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), &price_feed, 30); assert_balance(scenario, 1750 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); @@ -115,12 +133,49 @@ module registration::register_tests { test_scenario::end(scenario_val); } + #[test] + fun test_register_oracle() { + let scenario_val = test_init(); + let scenario = &mut scenario_val; + let price_feed = oracle_util(5000000); // $5 + + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 240 * mist_per_sui(), &price_feed, 10); + assert_balance(scenario, 240 * mist_per_sui()); + assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); + suins_registration::burn_for_testing(nft); + + let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 80 * mist_per_sui(), &price_feed, 20); + assert_balance(scenario, 320 * mist_per_sui()); + assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); + assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); + suins_registration::burn_for_testing(nft); + + let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 30 * mist_per_sui(), &price_feed, 30); + assert_balance(scenario, 350 * mist_per_sui()); + assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); + assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); + suins_registration::burn_for_testing(nft); + + + let price_feed = oracle_util(500000); // $0.5 + + let nft = register_util(scenario, utf8(b"abce-f123.sui"), 3, 300 * mist_per_sui(), &price_feed, 30); + assert_balance(scenario, 650 * mist_per_sui()); + assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f123.sui")), 0); + assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 90, 0); + suins_registration::burn_for_testing(nft); + + test_scenario::end(scenario_val); + } + #[test, expected_failure(abort_code = config::EInvalidTld)] fun test_register_if_not_sui_tld() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -130,8 +185,9 @@ module registration::register_tests { fun test_register_if_incorrect_amount() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1210 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1220 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -141,8 +197,33 @@ module registration::register_tests { fun test_register_if_incorrect_amount_2() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); + + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), &price_feed, 10); + suins_registration::burn_for_testing(nft); + + test_scenario::end(scenario_val); + } + + #[test, expected_failure(abort_code = register::EIncorrectAmount)] + fun test_register_if_incorrect_amount_with_oracle_too_few() { + let scenario_val = test_init(); + let scenario = &mut scenario_val; + let price_feed = oracle_util(1500000); // $1.50 + + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 150 * mist_per_sui(), &price_feed, 10); + suins_registration::burn_for_testing(nft); + + test_scenario::end(scenario_val); + } + + #[test, expected_failure(abort_code = register::EIncorrectAmount)] + fun test_register_if_incorrect_amount_with_oracle_too_much() { + let scenario_val = test_init(); + let scenario = &mut scenario_val; + let price_feed = oracle_util(1500000); // $1.50 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 250 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -152,8 +233,9 @@ module registration::register_tests { fun test_register_if_no_years_more_than_5_years() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -163,8 +245,9 @@ module registration::register_tests { fun test_register_if_no_years_is_zero() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -174,8 +257,9 @@ module registration::register_tests { fun test_register_if_expired() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); @@ -186,6 +270,7 @@ module registration::register_tests { utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), + &price_feed, year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 2400 * mist_per_sui()); @@ -203,14 +288,15 @@ module registration::register_tests { fun test_register_if_not_expired() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 20); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 20); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -220,8 +306,9 @@ module registration::register_tests { fun test_register_if_domain_name_starts_with_dash() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -231,8 +318,9 @@ module registration::register_tests { fun test_register_if_domain_name_ends_with_dash() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -242,8 +330,9 @@ module registration::register_tests { fun test_register_if_domain_name_contains_uppercase_character() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -253,8 +342,9 @@ module registration::register_tests { fun test_register_if_domain_name_too_short() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -264,8 +354,9 @@ module registration::register_tests { fun test_register_if_domain_name_contains_subdomain() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); - let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -276,9 +367,10 @@ module registration::register_tests { let scenario_val = test_init(); let scenario = &mut scenario_val; auction::init_for_testing(ctx(scenario)); + let price_feed = oracle_util(1000000); auction_tests::normal_auction_flow(scenario); - let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); @@ -289,6 +381,7 @@ module registration::register_tests { let scenario_val = test_init(); let scenario = &mut scenario_val; auction::init_for_testing(ctx(scenario)); + let price_feed = oracle_util(1000000); auction_tests::normal_auction_flow(scenario); let nft = register_util( @@ -296,6 +389,7 @@ module registration::register_tests { utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), + &price_feed, year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 50 * mist_per_sui()); @@ -309,9 +403,10 @@ module registration::register_tests { fun test_register_aborts_if_register_is_deauthorized() { let scenario_val = test_init(); let scenario = &mut scenario_val; + let price_feed = oracle_util(1000000); deauthorize_app_util(scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); suins_registration::burn_for_testing(nft); test_scenario::end(scenario_val); From 81b8bc54d64a5b97c162290093bdf18402ebef65 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Thu, 21 Mar 2024 11:23:31 -0400 Subject: [PATCH 02/14] price identifier assert --- packages/registration/sources/register.move | 15 +++++++++++++- .../registration/tests/register_tests.move | 20 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/registration/sources/register.move b/packages/registration/sources/register.move index 2ce8506c..528db586 100644 --- a/packages/registration/sources/register.move +++ b/packages/registration/sources/register.move @@ -16,6 +16,7 @@ module registration::register { use suins::suins_registration::SuinsRegistration; use pyth::price_feed::{Self, PriceFeed}; + use pyth::price_identifier; use pyth::price; use pyth::i64; @@ -24,6 +25,12 @@ module registration::register { /// Trying to register a subdomain (only *.sui is currently allowed). /// The payment does not match the price for the domain. const EIncorrectAmount: u64 = 4; + /// Pyth oracle reports a precision that's too high. + const EIncorrectPrecision: u64 = 5; + /// Incorrect price feed ID + const EIncorrectPriceFeedID: u64 = 6; + /// Sui Price Feed ID + const SUI_PRICE_FEED_ID: vector = x"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"; /// Authorization token for the app. struct Register has drop {} @@ -54,6 +61,10 @@ module registration::register { assert!(0 < no_years && no_years <= 5, EInvalidYearsArgument); let label = domain::sld(&domain); + + let price_identifier = &price_feed::get_price_identifier(price_feed); + let price_identifier_bytes = price_identifier::get_bytes(price_identifier); + assert!(price_identifier_bytes == SUI_PRICE_FEED_ID, EIncorrectPriceFeedID); let (sui_value_in_usd_lower_bound, sui_value_in_usd_upper_bound) = calculate_lower_upper_price(price_feed, coin::value(&payment)); let price_in_usd = config::calculate_price(config, (string::length(label) as u8), no_years); @@ -77,7 +88,9 @@ module registration::register { let sui_price_lower_bound = sui_price_u64 - price::get_conf(sui_price); let sui_price_upper_bound = sui_price_u64 + price::get_conf(sui_price); let exponent_i64 = &price::get_expo(sui_price); - let exponent_u8 = (i64::get_magnitude_if_negative(exponent_i64) as u8); + let exponent_u64 = i64::get_magnitude_if_negative(exponent_i64); + assert!(exponent_u64 < 256, EIncorrectPrecision); + let exponent_u8 = (exponent_u64 as u8); let sui_value_in_usd_lower_bound = sui_quantity * sui_price_lower_bound / (math::pow(10, exponent_u8)); let sui_value_in_usd_upper_bound = sui_quantity * sui_price_upper_bound / (math::pow(10, exponent_u8)); diff --git a/packages/registration/tests/register_tests.move b/packages/registration/tests/register_tests.move index 192a8ad3..12942426 100644 --- a/packages/registration/tests/register_tests.move +++ b/packages/registration/tests/register_tests.move @@ -58,7 +58,7 @@ module registration::register_tests { public fun oracle_util( desired_price_6_decimals: u64 ): PriceFeed { - let price_identifier = price_identifier::from_byte_vec(x"ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"); + let price_identifier = price_identifier::from_byte_vec(x"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"); let price_i64 = i64::new(desired_price_6_decimals, false); // ie: 1.610000 let expo_i64 = i64::new(6, true); // 10^-6 let price = price::new(price_i64, 10000, expo_i64, 0); // confidence is 1 cent @@ -253,6 +253,24 @@ module registration::register_tests { test_scenario::end(scenario_val); } + #[test, expected_failure(abort_code = register::EIncorrectPriceFeedID)] + fun test_register_incorrect_feed_id() { + let scenario_val = test_init(); + let scenario = &mut scenario_val; + + let price_identifier = price_identifier::from_byte_vec(x"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"); + let price_i64 = i64::new(1000000, false); // ie: 1.610000 + let expo_i64 = i64::new(6, true); // 10^-6 + let price = price::new(price_i64, 10000, expo_i64, 0); // confidence is 1 cent + let ema_price = copy(price); + let price_feed = price_feed::new(price_identifier, price, ema_price); + + let nft = register_util(scenario, utf8(DOMAIN_NAME), 3, 1200 * mist_per_sui(), &price_feed, 10); + suins_registration::burn_for_testing(nft); + + test_scenario::end(scenario_val); + } + #[test] fun test_register_if_expired() { let scenario_val = test_init(); From 5d429c22f38e70f169c11d1f7673004ca62b82ce Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Fri, 22 Mar 2024 14:22:23 -0400 Subject: [PATCH 03/14] unit tests --- packages/registration/Move.lock | 6 +- packages/registration/Move.toml | 2 +- packages/registration/sources/register.move | 25 ++-- .../registration/tests/register_tests.move | 134 +++++++++++------- 4 files changed, 101 insertions(+), 66 deletions(-) diff --git a/packages/registration/Move.lock b/packages/registration/Move.lock index 3a5a45ac..c948e134 100644 --- a/packages/registration/Move.lock +++ b/packages/registration/Move.lock @@ -2,7 +2,7 @@ [move] version = 0 -manifest_digest = "DF2D74504CBEBCC7EA362C169FB1A933D93EC1CE6FA96ACB465E13FE39349F72" +manifest_digest = "714124D2EC7F60B1BD3D39D85C3FDC9F6B1043B5ADFFAC92D5C7AE3C42F6BB18" deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" dependencies = [ @@ -17,7 +17,7 @@ source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdi [[move.package]] name = "Pyth" -source = { git = "https://github.com/pyth-network/pyth-crosschain.git", rev = "sui-contract-v0.0.2-mainnet-sui-1.19.1", subdir = "target_chains/sui/contracts" } +source = { git = "https://github.com/0xaslan/pyth-crosschain.git", rev = "sui/price-info-test", subdir = "target_chains/sui/contracts" } dependencies = [ { name = "Sui" }, @@ -34,7 +34,7 @@ dependencies = [ [[move.package]] name = "Wormhole" -source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "sui-upgrade-mainnet", subdir = "sui/wormhole" } +source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "82d82bffd5a8566e4b5d94be4e4678ad55ab1f4f", subdir = "sui/wormhole" } dependencies = [ { name = "Sui" }, diff --git a/packages/registration/Move.toml b/packages/registration/Move.toml index 9386aa03..51dd10e2 100644 --- a/packages/registration/Move.toml +++ b/packages/registration/Move.toml @@ -5,7 +5,7 @@ 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" } -Pyth = {git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/sui/contracts", rev = "sui-contract-v0.0.2-mainnet-sui-1.19.1"} +Pyth = {git = "https://github.com/0xaslan/pyth-crosschain.git", subdir = "target_chains/sui/contracts", rev = "sui/price-info-test"} [addresses] registration = "0x0" diff --git a/packages/registration/sources/register.move b/packages/registration/sources/register.move index 528db586..41a6a94e 100644 --- a/packages/registration/sources/register.move +++ b/packages/registration/sources/register.move @@ -16,7 +16,8 @@ module registration::register { use suins::suins_registration::SuinsRegistration; use pyth::price_feed::{Self, PriceFeed}; - use pyth::price_identifier; + use pyth::price_info::{Self, PriceInfoObject, PriceInfo}; + use pyth::price_identifier::{Self}; use pyth::price; use pyth::i64; @@ -30,7 +31,8 @@ module registration::register { /// Incorrect price feed ID const EIncorrectPriceFeedID: u64 = 6; /// Sui Price Feed ID - const SUI_PRICE_FEED_ID: vector = x"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"; + const SUI_PRICE_FEED_MAINNET_ID: vector = x"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"; + const SUI_PRICE_FEED_TESTNET_ID: vector = x"50c67b3fd225db8912a424dd4baed60ffdde625ed2feaaf283724f9608fea266"; /// Authorization token for the app. struct Register has drop {} @@ -47,7 +49,7 @@ module registration::register { domain_name: String, no_years: u8, payment: Coin, - price_feed: &PriceFeed, + price_info_object: &PriceInfoObject, clock: &Clock, ctx: &mut TxContext ): SuinsRegistration { @@ -60,12 +62,11 @@ module registration::register { assert!(0 < no_years && no_years <= 5, EInvalidYearsArgument); - let label = domain::sld(&domain); - - let price_identifier = &price_feed::get_price_identifier(price_feed); - let price_identifier_bytes = price_identifier::get_bytes(price_identifier); - assert!(price_identifier_bytes == SUI_PRICE_FEED_ID, EIncorrectPriceFeedID); + let price_info = &price_info::get_price_info_from_price_info_object(price_info_object); + validate_sui_price_feed(price_info); + let label = domain::sld(&domain); + let price_feed = price_info::get_price_feed(price_info); let (sui_value_in_usd_lower_bound, sui_value_in_usd_upper_bound) = calculate_lower_upper_price(price_feed, coin::value(&payment)); let price_in_usd = config::calculate_price(config, (string::length(label) as u8), no_years); @@ -77,6 +78,14 @@ module registration::register { registry::add_record(registry, domain, no_years, clock, ctx) } + fun validate_sui_price_feed( + price_info: &PriceInfo + ) { + let price_identifier = &price_info::get_price_identifier(price_info); + let price_id_bytes = price_identifier::get_bytes(price_identifier); + assert!(price_id_bytes == SUI_PRICE_FEED_MAINNET_ID || price_id_bytes == SUI_PRICE_FEED_TESTNET_ID, EIncorrectPriceFeedID); + } + fun calculate_lower_upper_price( price_feed: &PriceFeed, sui_quantity: u64 diff --git a/packages/registration/tests/register_tests.move b/packages/registration/tests/register_tests.move index 12942426..0e417ce2 100644 --- a/packages/registration/tests/register_tests.move +++ b/packages/registration/tests/register_tests.move @@ -23,7 +23,8 @@ module registration::register_tests { use suins::auction::{Self, App as AuctionApp}; use pyth::price_identifier; - use pyth::price_feed::{Self, PriceFeed}; + use pyth::price_feed; + use pyth::price_info::{Self, PriceInfoObject}; use pyth::price; use pyth::i64; @@ -56,14 +57,17 @@ module registration::register_tests { } public fun oracle_util( - desired_price_6_decimals: u64 - ): PriceFeed { + desired_price_6_decimals: u64, + scenario: &mut Scenario + ): PriceInfoObject { let price_identifier = price_identifier::from_byte_vec(x"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"); let price_i64 = i64::new(desired_price_6_decimals, false); // ie: 1.610000 let expo_i64 = i64::new(6, true); // 10^-6 let price = price::new(price_i64, 10000, expo_i64, 0); // confidence is 1 cent let ema_price = copy(price); - price_feed::new(price_identifier, price, ema_price) + let price_feed = price_feed::new(price_identifier, price, ema_price); + let price_info = price_info::new_price_info(0, 0, price_feed); + price_info::new_test_price_info_object(price_info, ctx(scenario)) } public fun register_util( @@ -71,7 +75,7 @@ module registration::register_tests { domain_name: String, no_years: u8, amount: u64, - price_feed: &PriceFeed, + price_info: &PriceInfoObject, clock_tick: u64 ): SuinsRegistration { test_scenario::next_tx(scenario, SUINS_ADDRESS); @@ -80,7 +84,7 @@ module registration::register_tests { let clock = test_scenario::take_shared(scenario); clock::increment_for_testing(&mut clock, clock_tick); - let nft = register(&mut suins, domain_name, no_years, payment, price_feed, &clock, ctx(scenario)); + let nft = register(&mut suins, domain_name, no_years, payment, price_info, &clock, ctx(scenario)); test_scenario::return_shared(clock); test_scenario::return_shared(suins); @@ -110,26 +114,27 @@ module registration::register_tests { fun test_register() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); // $1 + let price_info_object = oracle_util(1000000, scenario); // $1 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), &price_feed, 20); + let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), &price_info_object, 20); assert_balance(scenario, 1600 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), &price_feed, 30); + let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), &price_info_object, 30); assert_balance(scenario, 1750 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -137,35 +142,36 @@ module registration::register_tests { fun test_register_oracle() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(5000000); // $5 + let price_info_object = oracle_util(5000000, scenario); // $5 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 240 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 240 * mist_per_sui(), &price_info_object, 10); assert_balance(scenario, 240 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 80 * mist_per_sui(), &price_feed, 20); + let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 80 * mist_per_sui(), &price_info_object, 20); assert_balance(scenario, 320 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 30 * mist_per_sui(), &price_feed, 30); + let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 30 * mist_per_sui(), &price_info_object, 30); assert_balance(scenario, 350 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); + let price_info_object = oracle_util(500000, scenario); // $0.5 - let price_feed = oracle_util(500000); // $0.5 - - let nft = register_util(scenario, utf8(b"abce-f123.sui"), 3, 300 * mist_per_sui(), &price_feed, 30); + let nft = register_util(scenario, utf8(b"abce-f123.sui"), 3, 300 * mist_per_sui(), &price_info_object, 30); assert_balance(scenario, 650 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f123.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 90, 0); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -173,11 +179,12 @@ module registration::register_tests { fun test_register_if_not_sui_tld() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -185,11 +192,12 @@ module registration::register_tests { fun test_register_if_incorrect_amount() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1220 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1220 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -197,11 +205,12 @@ module registration::register_tests { fun test_register_if_incorrect_amount_2() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -209,11 +218,12 @@ module registration::register_tests { fun test_register_if_incorrect_amount_with_oracle_too_few() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1500000); // $1.50 + let price_info_object = oracle_util(1500000, scenario); // $1.50 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 150 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 150 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -221,11 +231,12 @@ module registration::register_tests { fun test_register_if_incorrect_amount_with_oracle_too_much() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1500000); // $1.50 + let price_info_object = oracle_util(1500000, scenario); // $1.50 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 250 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 250 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -233,11 +244,12 @@ module registration::register_tests { fun test_register_if_no_years_more_than_5_years() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -245,11 +257,12 @@ module registration::register_tests { fun test_register_if_no_years_is_zero() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -264,10 +277,13 @@ module registration::register_tests { let price = price::new(price_i64, 10000, expo_i64, 0); // confidence is 1 cent let ema_price = copy(price); let price_feed = price_feed::new(price_identifier, price, ema_price); + let price_info = price_info::new_price_info(0, 0, price_feed); + let price_info_object = price_info::new_test_price_info_object(price_info, ctx(scenario)); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 3, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 3, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -275,9 +291,9 @@ module registration::register_tests { fun test_register_if_expired() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); @@ -288,7 +304,7 @@ module registration::register_tests { utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), - &price_feed, + &price_info_object, year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 2400 * mist_per_sui()); @@ -299,6 +315,7 @@ module registration::register_tests { ); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -306,17 +323,18 @@ module registration::register_tests { fun test_register_if_not_expired() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 20); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 20); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -324,11 +342,12 @@ module registration::register_tests { fun test_register_if_domain_name_starts_with_dash() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -336,11 +355,12 @@ module registration::register_tests { fun test_register_if_domain_name_ends_with_dash() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -348,11 +368,12 @@ module registration::register_tests { fun test_register_if_domain_name_contains_uppercase_character() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -360,11 +381,12 @@ module registration::register_tests { fun test_register_if_domain_name_too_short() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -372,11 +394,12 @@ module registration::register_tests { fun test_register_if_domain_name_contains_subdomain() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -385,12 +408,13 @@ module registration::register_tests { let scenario_val = test_init(); let scenario = &mut scenario_val; auction::init_for_testing(ctx(scenario)); - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); auction_tests::normal_auction_flow(scenario); - let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -399,7 +423,7 @@ module registration::register_tests { let scenario_val = test_init(); let scenario = &mut scenario_val; auction::init_for_testing(ctx(scenario)); - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); auction_tests::normal_auction_flow(scenario); let nft = register_util( @@ -407,13 +431,14 @@ module registration::register_tests { utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), - &price_feed, + &price_info_object, year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 50 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(AUCTIONED_DOMAIN_NAME)), 0); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -421,12 +446,13 @@ module registration::register_tests { fun test_register_aborts_if_register_is_deauthorized() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_feed = oracle_util(1000000); + let price_info_object = oracle_util(1000000, scenario); deauthorize_app_util(scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_feed, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); suins_registration::burn_for_testing(nft); + price_info::destroy(price_info_object); test_scenario::end(scenario_val); } } From 1ad969a02a00de722f71ff171e4470d16568e1b4 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Mon, 25 Mar 2024 08:35:33 -0400 Subject: [PATCH 04/14] update all mysten packages --- scripts/airdrop/airdrop-mint.ts | 8 +- scripts/airdrop/airdrop-setup.ts | 6 +- scripts/airdrop/authorize-app.ts | 4 +- scripts/airdrop/coins.ts | 7 +- scripts/airdrop/deauthorize-app.ts | 4 +- scripts/airdrop/helper.ts | 64 ++-- scripts/config/constants.ts | 19 +- scripts/config/day_one.ts | 14 +- scripts/config/discounts.ts | 2 +- scripts/day_one/setup.ts | 8 +- scripts/package.json | 8 +- scripts/pnpm-lock.yaml | 347 ++++++++++++------ .../register_with_oracle.ts | 50 +++ scripts/reserved-names/objects.ts | 2 +- scripts/reserved-names/transfer-names.ts | 5 +- scripts/transactions/authorize_utils.ts | 4 +- ...uthorize_auction_authorize_registration.ts | 2 +- scripts/transactions/deepbook/create_pools.ts | 4 +- .../display_ipfs_to_google_storage.ts | 2 +- .../transactions/quest3/disable_discounts.ts | 4 +- .../quest3/disable_free_claims.ts | 4 +- scripts/transactions/quest_3_setup.ts | 5 +- .../transactions/withdraw_funds_20290927.ts | 2 +- 23 files changed, 383 insertions(+), 192 deletions(-) create mode 100644 scripts/register_with_oracle/register_with_oracle.ts diff --git a/scripts/airdrop/airdrop-mint.ts b/scripts/airdrop/airdrop-mint.ts index fae00bdb..0491c5b1 100644 --- a/scripts/airdrop/airdrop-mint.ts +++ b/scripts/airdrop/airdrop-mint.ts @@ -1,5 +1,7 @@ // TESTNET VERSION HERE. WILL CLEAN UP. -import { SuiObjectData, SuiObjectRef, SuiTransactionBlockResponse, TransactionBlock, getExecutionStatusType } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { SuiObjectData, SuiObjectRef } from "@mysten/sui.js/client"; +import { SuiTransactionBlockResponse } from "@mysten/sui.js/client"; import { MAX_MINTS_PER_TRANSACTION, addressesToBuffer, csvToBatches, executeTx, readAddressesFromFile } from './helper'; @@ -11,7 +13,7 @@ const SUI_COIN_TYPE = '0x2::coin::Coin<0x2::sui::SUI>'; const network = 'testnet' // change to mainnet when running it. -const signer = prepareSigner(mainPackage[network].provider); +const signer = prepareSigner(mainPackage[network].client); const config = addressConfig; const usedCoinObjects = new Set(); @@ -27,7 +29,7 @@ const prepareCoinObjects = async (chunks: number) => { const tx = new TransactionBlock(); // get the base gas coin from the provider - const { data } = await signer.provider.getObject({ + const { data } = await signer.client.getObject({ id: config.baseCoinObjectId }); diff --git a/scripts/airdrop/airdrop-setup.ts b/scripts/airdrop/airdrop-setup.ts index 895e2699..537b1a1d 100644 --- a/scripts/airdrop/airdrop-setup.ts +++ b/scripts/airdrop/airdrop-setup.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { batchToHash, executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { createDayOneDisplay, createDayOneTransferPolicy } from "../day_one/setup"; @@ -35,12 +35,12 @@ export const setupAirdrop = async (batches: string[][], network: Network): Promi // add the DayOne Display. createDayOneDisplay(tx, network); // attach TransferPolicy to make it tradeable. - await createDayOneTransferPolicy(tx, suinsPackageConfig.provider, network); + await createDayOneTransferPolicy(tx, suinsPackageConfig, network); // return if we're on multisig execution. if(airdropConfig.isMainnet) return tx; - const signer = prepareSigner(mainPackage[network].provider); + const signer = prepareSigner(mainPackage[network].client); await executeTx(signer, tx); } diff --git a/scripts/airdrop/authorize-app.ts b/scripts/airdrop/authorize-app.ts index 231118f6..3a712a89 100644 --- a/scripts/airdrop/authorize-app.ts +++ b/scripts/airdrop/authorize-app.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { Network, mainPackage } from "../config/constants"; @@ -21,7 +21,7 @@ export const authorizeBogoApp = async (network: Network): Promise let coins = []; while (hasNextPage) { - const data = await signer.provider.getAllCoins({ + const data = await signer.client.getAllCoins({ owner: config.massMintingAddress, cursor, limit: 50 @@ -32,7 +33,7 @@ export const cleanUpCoins = async (signer: RawSigner, config: AirdropConfig) => while (count > 1) { // get the base gas coin from the provider - const { data } = await signer.provider.getObject({ + const { data } = await signer.client.getObject({ id: config.baseCoinObjectId }); diff --git a/scripts/airdrop/deauthorize-app.ts b/scripts/airdrop/deauthorize-app.ts index 198f5940..749d37a6 100644 --- a/scripts/airdrop/deauthorize-app.ts +++ b/scripts/airdrop/deauthorize-app.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { Network, mainPackage } from "../config/constants"; @@ -21,7 +21,7 @@ export const deauthorizeBogoApp = async (network: Network): Promise { } -export const prepareSigner = (provider: JsonRpcProvider): RawSigner => { +export const prepareSigner = (client: SuiClient): RawSigner => { const phrase = process.env.ADMIN_PHRASE || ''; if (!phrase) throw new Error(`ERROR: Admin mnemonic is not exported! Please run 'export ADMIN_PHRASE=""'`); const keypair = Ed25519Keypair.deriveKeypair(phrase!); - return new RawSigner(keypair, provider); -} - -export const prepareSignerFromPrivateKey = (network: Network) => { - const privateKey = process.env.PRIVATE_KEY || ''; - if (!privateKey) throw new Error(`ERROR: Private key not exported or exported wrong! Please run 'export PRIVATE_KEY=""'`); - const keyPair: ExportedKeypair = { - schema: 'ED25519', - privateKey: toB64(fromHEX(privateKey)), - }; - - const config = mainPackage[network]; - return new RawSigner(fromExportedKeypair(keyPair), config.provider); + return new RawSigner(keypair, client); } // converts an array of addresses to a buffer using the `buffer` module. @@ -192,15 +184,15 @@ export const prepareMultisigTx = async ( tx.setSenderIfNotSet(config.adminAddress as string); // setting up gas object for the multi-sig transaction - if(gasObjectId) await setupGasPayment(tx, gasObjectId, config.provider); + if(gasObjectId) await setupGasPayment(tx, gasObjectId, config.client); // first do a dryRun, to make sure we are getting a success. - const dryRun = await inspectTransaction(tx, config.provider, network); + const dryRun = await inspectTransaction(tx, config.client, network); if(!dryRun) throw new Error("This transaction failed."); tx.build({ - provider: config.provider + client: config.client }).then((bytes) => { let serializedBase64 = toB64(bytes); @@ -212,8 +204,8 @@ export const prepareMultisigTx = async ( /* Fetch the gas Object and setup the payment for the tx. */ -const setupGasPayment = async (tx: TransactionBlock, gasObjectId: string, provider: JsonRpcProvider) => { - const gasObject = await provider.getObject({ +const setupGasPayment = async (tx: TransactionBlock, gasObjectId: string, client: SuiClient) => { + const gasObject = await client.getObject({ id: gasObjectId }); @@ -230,17 +222,25 @@ const setupGasPayment = async (tx: TransactionBlock, gasObjectId: string, provid /* A helper to dev inspect a transaction. */ -export const inspectTransaction = async (tx: TransactionBlock, provider: JsonRpcProvider, network: Network) => { +export const inspectTransaction = async (tx: TransactionBlock, client: SuiClient, network: Network) => { const config = mainPackage[network]; - const result = await provider.dryRunTransactionBlock({ - transactionBlock: await tx.build({ - provider - }) - }); + const result = await client.dryRunTransactionBlock( + { + transactionBlock: tx.serialize() + } + ); // log the result. console.dir(result, { depth: null }); - return getExecutionStatusType(result as SuiTransactionBlockResponse) === "success"; + return result.effects.status.status === 'success' +} +function getExecutionStatus(res: SuiTransactionBlockResponse): ExecutionStatus | undefined { + return res.effects?.status; +} + +function getExecutionStatusGasSummary(res: SuiTransactionBlockResponse): GasCostSummary | undefined { + return res.effects?.gasUsed; } + diff --git a/scripts/config/constants.ts b/scripts/config/constants.ts index db032a06..1230f7da 100644 --- a/scripts/config/constants.ts +++ b/scripts/config/constants.ts @@ -1,4 +1,5 @@ -import { Connection, JsonRpcProvider, ObjectId, SuiAddress, testnetConnection } from "@mysten/sui.js" +import { SuiClient } from "@mysten/sui.js/src/client"; +import { normalizeSuiAddress } from "@mysten/sui.js/src/utils"; export type Network = 'mainnet' | 'testnet' @@ -9,8 +10,8 @@ export type PackageInfo = { registrationPackageId: string; upgradeCap?: string; publisherId: string; - adminAddress: SuiAddress; - provider: JsonRpcProvider; + adminAddress: string; + client: SuiClient; adminCap: string; suins: string; displayObject?: string; @@ -27,13 +28,11 @@ export const mainPackage: Config = { registrationPackageId: '0x9d451fa0139fef8f7c1f0bd5d7e45b7fa9dbb84c2e63c2819c7abd0a7f7d749d', upgradeCap: '0x9cda28244a0d0de294d2b271e772a9c33eb47d316c59913d7369b545b4af098c', publisherId: '0x7339f23f06df3601167d67a31752781d307136fd18304c48c928778e752caae1', - adminAddress: '0xa81a2328b7bbf70ab196d6aca400b5b0721dec7615bf272d95e0b0df04517e72', + adminAddress: normalizeSuiAddress('0xa81a2328b7bbf70ab196d6aca400b5b0721dec7615bf272d95e0b0df04517e72'), adminCap: '0x3f8d702d90c572b60ac692fb5074f7a7ac350b80d9c59eab4f6b7692786cae0a', suins: '0x6e0ddefc0ad98889c04bab9639e512c21766c5e6366f89e696956d9be6952871', displayObject: '0x866fbd8e51b6637c25f0e811ece9a85eb417f3987ecdfefb80f15d1192d72b4c', - provider: new JsonRpcProvider(new Connection({ - fullnode: 'https://suins-rpc.mainnet.sui.io' - })), + client: new SuiClient({ url: 'https://suins-rpc.mainnet.sui.io'}), discountsPackage: { packageId: '0x6a6ea140e095ddd82f7c745905054b3203129dd04a09d0375416c31161932d2d', discountHouseId: '0x7fdd883c0b7427f18cdb498c4c87a4a79d6bec4783cb3f21aa3816bbc64ce8ef', @@ -46,11 +45,9 @@ export const mainPackage: Config = { registrationPackageId: 'TODO: Fill this in', publisherId: '0xd12afb9b5e4a8dc875d22fc927e78952dc9bd84730b33c02e9fd30949c100e38', adminAddress: '0x7bdfc33239bd05af27d6989cee5455da4bc69ed4cfab5d178434a96ff412514a', - adminCap: '0xadc8b4c3fa0cc022e995968e06fca1d4a47f782f7bb0e88c52730eca77cdae03', + adminCap: normalizeSuiAddress('0xadc8b4c3fa0cc022e995968e06fca1d4a47f782f7bb0e88c52730eca77cdae03'), suins: '0xedc672fadedee348108618da7555f771d4fec8d3331779a8411ff8184aded726', - provider: new JsonRpcProvider(new Connection({ - fullnode: 'https://suins-rpc.testnet.sui.io:443' - })), + client: new SuiClient({ url: 'https://suins-rpc.testnet.sui.io:443'}), directSetupPackageId: '0x9af70a4cb6d7144e68fd972eef672a74c7fe41aa5c0bb67ba40d7d1ae87bfb19', discountsPackage: { packageId: '0x319364827e018833f545d8291f0482c5859ead75663543dda153b50df83244eb', diff --git a/scripts/config/day_one.ts b/scripts/config/day_one.ts index daa78ed5..d3357256 100644 --- a/scripts/config/day_one.ts +++ b/scripts/config/day_one.ts @@ -1,18 +1,16 @@ -import { ObjectId, SuiAddress } from "@mysten/sui.js"; - export type AirdropConfig = { isMainnet?: boolean; packageId: string; dropListObj: { - objectId: ObjectId, + objectId: string, initialSharedVersion: string; mutable: boolean; }, - setupCap: ObjectId; - massMintingAddress: SuiAddress; - baseCoinObjectId: ObjectId; - publisher: ObjectId; - bufferPackageId: ObjectId; + setupCap: string; + massMintingAddress: string; + baseCoinObjectId: string; + publisher: string; + bufferPackageId: string; } export const mainnetConfig: AirdropConfig = { diff --git a/scripts/config/discounts.ts b/scripts/config/discounts.ts index ac2b992a..f5789324 100644 --- a/scripts/config/discounts.ts +++ b/scripts/config/discounts.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, PackageInfo } from "./constants"; export const SUIFREN_BULLSHARK_TYPE: Record = { diff --git a/scripts/day_one/setup.ts b/scripts/day_one/setup.ts index 9e5c0d60..88805595 100644 --- a/scripts/day_one/setup.ts +++ b/scripts/day_one/setup.ts @@ -1,4 +1,5 @@ -import { JsonRpcProvider, TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { SuiClient } from "@mysten/sui.js/client" import { Network, mainPackage } from "../config/constants"; import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one"; import { createTransferPolicy, queryTransferPolicy } from "@mysten/kiosk"; @@ -44,14 +45,14 @@ export const createDayOneDisplay = async (tx: TransactionBlock, network: Network export const createDayOneTransferPolicy = async ( tx: TransactionBlock, - provider: JsonRpcProvider, + client: SuiClient, network: Network, ) => { const config = network === 'mainnet' ? mainnetConfig : addressConfig; const mainPackageConfig = mainPackage[network]; - const existingPolicy = await queryTransferPolicy(provider, dayOneType(config)); + const existingPolicy = await queryTransferPolicy(client, dayOneType(config)); if (existingPolicy.length > 0) { console.warn(`Type ${dayOneType} already had a tranfer policy so the transaction was skipped.`); @@ -64,5 +65,4 @@ export const createDayOneTransferPolicy = async ( tx.transferObjects([transferPolicyCap], tx.pure(mainPackageConfig.adminAddress, 'address')); return true; - } diff --git a/scripts/package.json b/scripts/package.json index 447d1340..cfb1e891 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -22,11 +22,11 @@ "author": "", "license": "ISC", "dependencies": { - "@mysten/bcs": "^0.7.3", - "@mysten/kiosk": "^0.3.3", - "@mysten/sui.js": "^0.37.1", + "@mysten/bcs": "0.11.1", + "@mysten/kiosk": "0.8.4", + "@mysten/sui.js": "0.51.0", "@types/blake2": "^4.0.1", - "blake2": "^5.0.0", + "@pythnetwork/pyth-sui-js": "2.0.0", "dotenv": "^16.3.1", "ts-node": "^10.9.1", "typescript": "^5.1.6" diff --git a/scripts/pnpm-lock.yaml b/scripts/pnpm-lock.yaml index 8440a7a6..f59bcd5f 100644 --- a/scripts/pnpm-lock.yaml +++ b/scripts/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -6,20 +6,20 @@ settings: dependencies: '@mysten/bcs': - specifier: ^0.7.3 - version: 0.7.3 + specifier: 0.11.1 + version: 0.11.1 '@mysten/kiosk': - specifier: ^0.3.3 - version: 0.3.3 + specifier: 0.8.4 + version: 0.8.4 '@mysten/sui.js': - specifier: ^0.37.1 - version: 0.37.1 + specifier: 0.51.0 + version: 0.51.0 + '@pythnetwork/pyth-sui-js': + specifier: 2.0.0 + version: 2.0.0 '@types/blake2': specifier: ^4.0.1 version: 4.0.1 - blake2: - specifier: ^5.0.0 - version: 5.0.0 dotenv: specifier: ^16.3.1 version: 16.3.1 @@ -32,6 +32,24 @@ dependencies: packages: + /@0no-co/graphql.web@1.0.4(graphql@16.8.1): + resolution: {integrity: sha512-W3ezhHGfO0MS1PtGloaTpg0PbaT8aZSmmaerL7idtU5F7oCI+uu25k+MsMS31BVFlp4aMkHSrNRxiD72IlK8TA==} + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 + peerDependenciesMeta: + graphql: + optional: true + dependencies: + graphql: 16.8.1 + dev: false + + /@babel/runtime@7.24.1: + resolution: {integrity: sha512-+BIznRzyqBf+2wCTxcKE3wDjfGeCoVE61KSHGpkzqrLi8qxqFwBeUFyId2cxkTmm55fzDGnm0+yCxaxygrLUnQ==} + engines: {node: '>=6.9.0'} + dependencies: + regenerator-runtime: 0.14.1 + dev: false + /@cspotcode/source-map-support@0.8.1: resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} @@ -39,6 +57,28 @@ packages: '@jridgewell/trace-mapping': 0.3.9 dev: false + /@gql.tada/cli-utils@0.3.0: + resolution: {integrity: sha512-kDebLVuM5r3/bI1MmlhHr9VKHxXeq8Gxy1wHVTPva4R5ObfbhzxnHsTCvR6MUp8ziy9Pg9MESb8S1YZW8ohM3A==} + dependencies: + '@gql.tada/internal': 0.1.0 + graphql: 16.8.1 + dev: false + + /@gql.tada/internal@0.1.0: + resolution: {integrity: sha512-FTvBVXVvt0xUo8hvRlwFoyeNXpUDqc+e20MzFkF8ozbsa5PoYb/gksmmnHMjUphsIq1H3Hq8o4RGstFN5LKH4w==} + dependencies: + graphql: 16.8.1 + typescript: 5.4.3 + dev: false + + /@graphql-typed-document-node/core@3.2.0(graphql@16.8.1): + resolution: {integrity: sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==} + peerDependencies: + graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 + dependencies: + graphql: 16.8.1 + dev: false + /@jridgewell/resolve-uri@3.1.1: resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==} engines: {node: '>=6.0.0'} @@ -55,57 +95,61 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: false - /@mysten/bcs@0.7.3: - resolution: {integrity: sha512-fbusBfsyc2MpTACi72H5edWJ670T84va+qn9jSPpb5BzZ+pzUM1Q0ApPrF5OT+mB1o5Ng+mxPQpBCZQkfiV2TA==} + /@mysten/bcs@0.10.1: + resolution: {integrity: sha512-cQDb7Rhz2J82ZqgVQiHykuwKUlgiLWS2bjoajPPW0uvXlb75qrgKuaxh1UzsaRhHy3egk/APc0xjiZoqdbzB4w==} dependencies: bs58: 5.0.0 dev: false - /@mysten/kiosk@0.3.3: - resolution: {integrity: sha512-SlZpYNwrI/twx0V+ES6S0R7h4zjujmig9ZILFnnTHFuyJG5So4NSnbNtI7yNfkedrPnJjoNokv5YoF20hm9GMQ==} + /@mysten/bcs@0.11.1: + resolution: {integrity: sha512-xP85isNSYUCHd3O/g+TmZYmg4wK6cU8q/n/MebkIGP4CYVJZz2wU/G24xIZ3wI+0iTop4dfgA5kYrg/DQKCUzA==} + dependencies: + bs58: 5.0.0 + dev: false + + /@mysten/kiosk@0.8.4: + resolution: {integrity: sha512-RtiNvjWo/EoYOE9IimseBwC6th/nmFm3kIZmkWGa6pjbO+Ai+YfpSMdUOvtGdkhDXHjugdATAGblgxEZTNk2ew==} engines: {node: '>=16'} dependencies: - '@mysten/sui.js': 0.37.1 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate + '@mysten/sui.js': 0.51.0 dev: false - /@mysten/sui.js@0.37.1: - resolution: {integrity: sha512-nEOqnjUqb/VJcVk23LgZOX1FmBib/mBCwAWaJhtsCHLwv2jIAfCPY/fpB9lJ62QHrM8UFclpWxsLkqcUkKyPgA==} + /@mysten/sui.js@0.49.1: + resolution: {integrity: sha512-xMndhhlnlVYjMVmBkXnGs9wdw7/bh3R/QggD/DkqGG7Iq7RL2uldtAeIFYsPGfTua/TJW8RFX7q59RagIOwWdw==} engines: {node: '>=16'} dependencies: - '@mysten/bcs': 0.7.3 - '@noble/curves': 1.1.0 - '@noble/hashes': 1.3.1 - '@open-rpc/client-js': 1.8.1 - '@scure/bip32': 1.3.0 + '@mysten/bcs': 0.10.1 + '@noble/curves': 1.4.0 + '@noble/hashes': 1.4.0 + '@scure/bip32': 1.4.0 '@scure/bip39': 1.2.1 '@suchipi/femver': 1.0.0 - events: 3.3.0 superstruct: 1.0.3 tweetnacl: 1.0.3 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate dev: false - /@noble/curves@1.0.0: - resolution: {integrity: sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==} + /@mysten/sui.js@0.51.0: + resolution: {integrity: sha512-/D/JDE+dgL1Nc6/Ju32bIrTr5XYcYdYMHzhgRk+f8nGf3eZRGaWIphN9VEBXjn+4F8M9/t3BKLfITWrQ2o3++w==} + engines: {node: '>=16'} dependencies: - '@noble/hashes': 1.3.0 + '@graphql-typed-document-node/core': 3.2.0(graphql@16.8.1) + '@mysten/bcs': 0.11.1 + '@noble/curves': 1.4.0 + '@noble/hashes': 1.4.0 + '@scure/bip32': 1.4.0 + '@scure/bip39': 1.2.1 + '@suchipi/femver': 1.0.0 + bech32: 2.0.0 + gql.tada: 1.4.0(graphql@16.8.1) + graphql: 16.8.1 + superstruct: 1.0.3 + tweetnacl: 1.0.3 dev: false - /@noble/curves@1.1.0: - resolution: {integrity: sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==} + /@noble/curves@1.4.0: + resolution: {integrity: sha512-p+4cb332SFCrReJkCYe8Xzm0OWi4Jji5jVdIZRL/PmacmDkFNw6MrrV+gGpiPxLHbV+zKFRywUWbaseT+tZRXg==} dependencies: - '@noble/hashes': 1.3.1 - dev: false - - /@noble/hashes@1.3.0: - resolution: {integrity: sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==} + '@noble/hashes': 1.4.0 dev: false /@noble/hashes@1.3.1: @@ -113,16 +157,40 @@ packages: engines: {node: '>= 16'} dev: false - /@open-rpc/client-js@1.8.1: - resolution: {integrity: sha512-vV+Hetl688nY/oWI9IFY0iKDrWuLdYhf7OIKI6U1DcnJV7r4gAgwRJjEr1QVYszUc0gjkHoQJzqevmXMGLyA0g==} + /@noble/hashes@1.4.0: + resolution: {integrity: sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==} + engines: {node: '>= 16'} + dev: false + + /@pythnetwork/price-service-client@1.9.0: + resolution: {integrity: sha512-SLm3IFcfmy9iMqHeT4Ih6qMNZhJEefY14T9yTlpsH2D/FE5+BaGGnfcexUifVlfH6M7mwRC4hEFdNvZ6ebZjJg==} dependencies: - isomorphic-fetch: 3.0.0 - isomorphic-ws: 5.0.0(ws@7.5.9) - strict-event-emitter-types: 2.0.0 - ws: 7.5.9 + '@pythnetwork/price-service-sdk': 1.6.0 + '@types/ws': 8.5.10 + axios: 1.6.8 + axios-retry: 3.9.1 + isomorphic-ws: 4.0.1(ws@8.16.0) + ts-log: 2.2.5 + ws: 8.16.0 transitivePeerDependencies: - bufferutil - - encoding + - debug + - utf-8-validate + dev: false + + /@pythnetwork/price-service-sdk@1.6.0: + resolution: {integrity: sha512-3mtlxvT/V3uCqmAGFTRAoJ4u0AXGHgIZVBs4uyRxysURTgywJk4yxoD3xPhaUjd5sfRTon546ZZ67L7oyUFMUg==} + dev: false + + /@pythnetwork/pyth-sui-js@2.0.0: + resolution: {integrity: sha512-uCFnEXxHaux4SfAAdzBBuoQ6gbDElmml0lh2Vargn0uahXfbp/JY47bGCSwAZw5jGH9qFYIUHl7+wUS/jwf6oQ==} + dependencies: + '@mysten/sui.js': 0.49.1 + '@pythnetwork/price-service-client': 1.9.0 + buffer: 6.0.3 + transitivePeerDependencies: + - bufferutil + - debug - utf-8-validate dev: false @@ -130,12 +198,16 @@ packages: resolution: {integrity: sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==} dev: false - /@scure/bip32@1.3.0: - resolution: {integrity: sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==} + /@scure/base@1.1.6: + resolution: {integrity: sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g==} + dev: false + + /@scure/bip32@1.4.0: + resolution: {integrity: sha512-sVUpc0Vq3tXCkDGYVWGIZTRfnvu8LoTDaev7vbwh0omSvVORONr960MQWdKqJDCReIEmTj3PAr73O3aoxz7OPg==} dependencies: - '@noble/curves': 1.0.0 - '@noble/hashes': 1.3.1 - '@scure/base': 1.1.1 + '@noble/curves': 1.4.0 + '@noble/hashes': 1.4.0 + '@scure/base': 1.1.6 dev: false /@scure/bip39@1.2.1: @@ -175,6 +247,12 @@ packages: resolution: {integrity: sha512-wheIYdr4NYML61AjC8MKj/2jrR/kDQri/CIpVoZwldwhnIrD/j9jIU5bJ8yBKuB2VhpFV7Ab6G2XkBjv9r9Zzw==} dev: false + /@types/ws@8.5.10: + resolution: {integrity: sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==} + dependencies: + '@types/node': 20.3.3 + dev: false + /acorn-walk@8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} @@ -190,16 +268,37 @@ packages: resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} dev: false + /asynckit@0.4.0: + resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + dev: false + + /axios-retry@3.9.1: + resolution: {integrity: sha512-8PJDLJv7qTTMMwdnbMvrLYuvB47M81wRtxQmEdV5w4rgbTXTt+vtPkXwajOfOdSyv/wZICJOC+/UhXH4aQ/R+w==} + dependencies: + '@babel/runtime': 7.24.1 + is-retry-allowed: 2.2.0 + dev: false + + /axios@1.6.8: + resolution: {integrity: sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==} + dependencies: + follow-redirects: 1.15.6 + form-data: 4.0.0 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + dev: false + /base-x@4.0.0: resolution: {integrity: sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==} dev: false - /blake2@5.0.0: - resolution: {integrity: sha512-MLpq1DwBB9rC0IHuRc2gXLEAeNNTTYHEtvYCA5lK4RmoUPRmQLSLQrwgJvou62BvH9KP7whe8n+xxw45++fnYg==} - engines: {node: '>= 12.0.0'} - requiresBuild: true - dependencies: - nan: 2.17.0 + /base64-js@1.5.1: + resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + dev: false + + /bech32@2.0.0: + resolution: {integrity: sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==} dev: false /bs58@5.0.0: @@ -208,10 +307,29 @@ packages: base-x: 4.0.0 dev: false + /buffer@6.0.3: + resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + dev: false + + /combined-stream@1.0.8: + resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} + engines: {node: '>= 0.8'} + dependencies: + delayed-stream: 1.0.0 + dev: false + /create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} dev: false + /delayed-stream@1.0.0: + resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} + engines: {node: '>=0.4.0'} + dev: false + /diff@4.0.2: resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} engines: {node: '>=0.3.1'} @@ -222,50 +340,80 @@ packages: engines: {node: '>=12'} dev: false - /events@3.3.0: - resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} - engines: {node: '>=0.8.x'} + /follow-redirects@1.15.6: + resolution: {integrity: sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true dev: false - /isomorphic-fetch@3.0.0: - resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==} + /form-data@4.0.0: + resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} + engines: {node: '>= 6'} dependencies: - node-fetch: 2.6.12 - whatwg-fetch: 3.6.2 + asynckit: 0.4.0 + combined-stream: 1.0.8 + mime-types: 2.1.35 + dev: false + + /gql.tada@1.4.0(graphql@16.8.1): + resolution: {integrity: sha512-/LZJmInJQESn0QafOrDCJRk9ASeI65caU/HmarPtcSNitNWBrH7UfNOsHtISnTTA/CS80eUYqy3M4ogasFZWPQ==} + hasBin: true + dependencies: + '@0no-co/graphql.web': 1.0.4(graphql@16.8.1) + '@gql.tada/cli-utils': 0.3.0 + '@gql.tada/internal': 0.1.0 transitivePeerDependencies: - - encoding + - graphql dev: false - /isomorphic-ws@5.0.0(ws@7.5.9): - resolution: {integrity: sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==} + /graphql@16.8.1: + resolution: {integrity: sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==} + engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0} + dev: false + + /ieee754@1.2.1: + resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + dev: false + + /is-retry-allowed@2.2.0: + resolution: {integrity: sha512-XVm7LOeLpTW4jV19QSH38vkswxoLud8sQ57YwJVTPWdiaI9I8keEhGFpBlslyVsgdQy4Opg8QOLb8YRgsyZiQg==} + engines: {node: '>=10'} + dev: false + + /isomorphic-ws@4.0.1(ws@8.16.0): + resolution: {integrity: sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==} peerDependencies: ws: '*' dependencies: - ws: 7.5.9 + ws: 8.16.0 dev: false /make-error@1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} dev: false - /nan@2.17.0: - resolution: {integrity: sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==} + /mime-db@1.52.0: + resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} + engines: {node: '>= 0.6'} dev: false - /node-fetch@2.6.12: - resolution: {integrity: sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==} - engines: {node: 4.x || >=6.0.0} - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true + /mime-types@2.1.35: + resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} + engines: {node: '>= 0.6'} dependencies: - whatwg-url: 5.0.0 + mime-db: 1.52.0 dev: false - /strict-event-emitter-types@2.0.0: - resolution: {integrity: sha512-Nk/brWYpD85WlOgzw5h173aci0Teyv8YdIAEtV+N88nDB0dLlazZyJMIsN6eo1/AR61l+p6CJTG1JIyFaoNEEA==} + /proxy-from-env@1.1.0: + resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} + dev: false + + /regenerator-runtime@0.14.1: + resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} dev: false /superstruct@1.0.3: @@ -273,8 +421,8 @@ packages: engines: {node: '>=14.0.0'} dev: false - /tr46@0.0.3: - resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} + /ts-log@2.2.5: + resolution: {integrity: sha512-PGcnJoTBnVGy6yYNFxWVNkdcAuAMstvutN9MgDJIV6L0oG8fB+ZNNy1T+wJzah8RPGor1mZuPQkVfXNDpy9eHA==} dev: false /ts-node@10.9.1(@types/node@20.3.3)(typescript@5.1.6): @@ -318,31 +466,22 @@ packages: hasBin: true dev: false - /v8-compile-cache-lib@3.0.1: - resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - dev: false - - /webidl-conversions@3.0.1: - resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - dev: false - - /whatwg-fetch@3.6.2: - resolution: {integrity: sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==} + /typescript@5.4.3: + resolution: {integrity: sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==} + engines: {node: '>=14.17'} + hasBin: true dev: false - /whatwg-url@5.0.0: - resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 + /v8-compile-cache-lib@3.0.1: + resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} dev: false - /ws@7.5.9: - resolution: {integrity: sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==} - engines: {node: '>=8.3.0'} + /ws@8.16.0: + resolution: {integrity: sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==} + engines: {node: '>=10.0.0'} peerDependencies: bufferutil: ^4.0.1 - utf-8-validate: ^5.0.2 + utf-8-validate: '>=5.0.2' peerDependenciesMeta: bufferutil: optional: true diff --git a/scripts/register_with_oracle/register_with_oracle.ts b/scripts/register_with_oracle/register_with_oracle.ts new file mode 100644 index 00000000..5a3ed58d --- /dev/null +++ b/scripts/register_with_oracle/register_with_oracle.ts @@ -0,0 +1,50 @@ +import { mainPackage } from "../config/constants"; +import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js"; +import dotenv from "dotenv"; +import { executeTx, prepareSigner } from "../airdrop/helper"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { SuiClient } from "@mysten/sui.js/client"; +dotenv.config(); + +const setup = async () => { + const connection = new SuiPriceServiceConnection( + "https://hermes-beta.pyth.network" + ); + // You can find the ids of prices at https://pyth.network/developers/price-feed-ids + const priceIds = ["0x50c67b3fd225db8912a424dd4baed60ffdde625ed2feaaf283724f9608fea266"]; // SUI/USD + + // In order to use Pyth prices in your protocol you need to submit the price update data to Pyth contract in your target + // chain. `getPriceUpdateData` creates the update data which can be submitted to your contract. + const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIds); + + // https://docs.pyth.network/price-feeds/contract-addresses/sui + const wormholeStateId = "0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02"; + const pythStateId = "0x2d82612a354f0b7e52809fc2845642911c7190404620cec8688f68808f8800d8"; + + let suiClient = new SuiClient({ + url: "https://suins-rpc.testnet.sui.io:443" + }); + const client = new SuiPythClient(suiClient, pythStateId, wormholeStateId); + const txb = new TransactionBlock(); + let priceInfoObjectIds = await client.updatePriceFeeds(txb, priceUpdateData, priceIds); + + const setup = mainPackage["testnet"]; + const [sui_coin] = txb.splitCoins(txb.gas, [txb.pure(20)]); + const nft = txb.moveCall({ + target: `${setup.registrationPackageId}::register::register`, + arguments: [ + txb.object(setup.suins), // suins: &mut SuiNS + txb.object("test_domain"), // domain_name: String + txb.pure(1), // no_years: u8 + sui_coin, // payment: Coin + txb.object(priceInfoObjectIds[0]), // price_info_object: &PriceInfoObject + // clock: &Clock + // ctx: &mut TxContext + ], + }); + txb.transferObjects([nft], txb.pure.address('insert_address')) // send to tx sender + + return executeTx(prepareSigner(setup.client), txb); +}; + +setup(); \ No newline at end of file diff --git a/scripts/reserved-names/objects.ts b/scripts/reserved-names/objects.ts index 32f70818..29cef87f 100644 --- a/scripts/reserved-names/objects.ts +++ b/scripts/reserved-names/objects.ts @@ -11,7 +11,7 @@ const getAllOwnedDomains = async () => { let names = []; while(hasNextPage){ - const res = await config.provider.getOwnedObjects({ + const res = await config.client.getOwnedObjects({ owner: config.adminAddress, filter: { MatchAll: [ diff --git a/scripts/reserved-names/transfer-names.ts b/scripts/reserved-names/transfer-names.ts index 53002ca1..2995a121 100644 --- a/scripts/reserved-names/transfer-names.ts +++ b/scripts/reserved-names/transfer-names.ts @@ -1,4 +1,7 @@ -import { SuiObjectResponse, TransactionBlock, isValidSuiAddress } from "@mysten/sui.js"; +import { SuiObjectResponse } from "@mysten/sui.js/client"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { isValidSuiAddress } from "@mysten/sui.js/utils"; + import fs from "fs"; import { prepareMultisigTx } from "../airdrop/helper"; diff --git a/scripts/transactions/authorize_utils.ts b/scripts/transactions/authorize_utils.ts index 339e85fa..62a3e822 100644 --- a/scripts/transactions/authorize_utils.ts +++ b/scripts/transactions/authorize_utils.ts @@ -4,7 +4,7 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, mainPackage } from "../config/constants"; export const authorizeDirectSetupApp = async (network: Network) => { @@ -25,7 +25,7 @@ export const authorizeDirectSetupApp = async (network: Network) => { // for mainnet, we just prepare multisig TX if(network === 'mainnet') return prepareMultisigTx(tx, 'mainnet'); - return executeTx(prepareSigner(config.provider), tx); + return executeTx(prepareSigner(config.client), tx); // prepare tx data. } diff --git a/scripts/transactions/deauthorize_auction_authorize_registration.ts b/scripts/transactions/deauthorize_auction_authorize_registration.ts index 55a0206a..04f1e50b 100644 --- a/scripts/transactions/deauthorize_auction_authorize_registration.ts +++ b/scripts/transactions/deauthorize_auction_authorize_registration.ts @@ -4,7 +4,7 @@ import dotenv from "dotenv"; dotenv.config(); import { prepareMultisigTx } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { mainPackage } from "../config/constants"; const migrateToDirectRegistration = async () => { diff --git a/scripts/transactions/deepbook/create_pools.ts b/scripts/transactions/deepbook/create_pools.ts index 9a04048c..fcd70a68 100644 --- a/scripts/transactions/deepbook/create_pools.ts +++ b/scripts/transactions/deepbook/create_pools.ts @@ -9,7 +9,7 @@ import { prepareSigner, } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; const SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"; @@ -148,7 +148,7 @@ const setup = async (network: Network) => { if (network === "mainnet") return prepareMultisigTx(txb, "mainnet"); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.provider), txb); + return executeTx(prepareSigner(setup.client), txb); }; if (process.env.NETWORK === "mainnet") setup("mainnet"); diff --git a/scripts/transactions/display_ipfs_to_google_storage.ts b/scripts/transactions/display_ipfs_to_google_storage.ts index 50cae7b4..82de9f69 100644 --- a/scripts/transactions/display_ipfs_to_google_storage.ts +++ b/scripts/transactions/display_ipfs_to_google_storage.ts @@ -5,7 +5,7 @@ import dotenv from "dotenv"; dotenv.config(); import { prepareMultisigTx } from "../airdrop/helper"; import { authorizeBogoApp } from "../airdrop/authorize-app"; -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { mainPackage } from "../config/constants"; const run = async () => { diff --git a/scripts/transactions/quest3/disable_discounts.ts b/scripts/transactions/quest3/disable_discounts.ts index cc749744..6b923df2 100644 --- a/scripts/transactions/quest3/disable_discounts.ts +++ b/scripts/transactions/quest3/disable_discounts.ts @@ -5,7 +5,7 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { DAY_ONE_TYPE, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeDiscountForType } from "../../config/discounts"; const execute = async (network: Network) => { @@ -21,7 +21,7 @@ const execute = async (network: Network) => { if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.provider), txb); + return executeTx(prepareSigner(setup.client), txb); } if(process.env.NETWORK === 'mainnet') execute('mainnet') diff --git a/scripts/transactions/quest3/disable_free_claims.ts b/scripts/transactions/quest3/disable_free_claims.ts index 66cfb538..916c648a 100644 --- a/scripts/transactions/quest3/disable_free_claims.ts +++ b/scripts/transactions/quest3/disable_free_claims.ts @@ -5,7 +5,7 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { DAY_ONE_TYPE, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeFreeClaimsForType, setupDiscountForType } from "../../config/discounts"; // Setup Quests 3. @@ -22,7 +22,7 @@ const setup = async (network: Network) => { if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.provider), txb); + return executeTx(prepareSigner(setup.client), txb); } if(process.env.NETWORK === 'mainnet') setup('mainnet') diff --git a/scripts/transactions/quest_3_setup.ts b/scripts/transactions/quest_3_setup.ts index c83d8dae..8189492c 100644 --- a/scripts/transactions/quest_3_setup.ts +++ b/scripts/transactions/quest_3_setup.ts @@ -5,7 +5,8 @@ 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"; +import { MIST_PER_SUI } from '@mysten/sui.js/utils'; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { DAY_ONE_TYPE, Discount, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeDiscountForType, setupDiscountForType } from "../config/discounts"; // Setup Quests 3. @@ -51,7 +52,7 @@ const setup = async (network: Network) => { if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.provider), txb); + return executeTx(prepareSigner(setup.client), txb); } if(process.env.NETWORK === 'mainnet') setup('mainnet') diff --git a/scripts/transactions/withdraw_funds_20290927.ts b/scripts/transactions/withdraw_funds_20290927.ts index 35991618..74e737c7 100644 --- a/scripts/transactions/withdraw_funds_20290927.ts +++ b/scripts/transactions/withdraw_funds_20290927.ts @@ -1,7 +1,7 @@ // Copyright (c) 2023, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { TransactionBlock } from '@mysten/sui.js'; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { mainPackage } from '../config/constants'; import { prepareMultisigTx } from '../airdrop/helper'; From 62a655073188bfd486326905868c0aa5bf356ff5 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Mon, 25 Mar 2024 08:42:24 -0400 Subject: [PATCH 05/14] fix --- scripts/airdrop/airdrop-setup.ts | 2 +- scripts/day_one/setup.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/airdrop/airdrop-setup.ts b/scripts/airdrop/airdrop-setup.ts index 537b1a1d..7ee0419b 100644 --- a/scripts/airdrop/airdrop-setup.ts +++ b/scripts/airdrop/airdrop-setup.ts @@ -35,7 +35,7 @@ export const setupAirdrop = async (batches: string[][], network: Network): Promi // add the DayOne Display. createDayOneDisplay(tx, network); // attach TransferPolicy to make it tradeable. - await createDayOneTransferPolicy(tx, suinsPackageConfig, network); + await createDayOneTransferPolicy(tx, network); // return if we're on multisig execution. if(airdropConfig.isMainnet) return tx; diff --git a/scripts/day_one/setup.ts b/scripts/day_one/setup.ts index 88805595..84370aca 100644 --- a/scripts/day_one/setup.ts +++ b/scripts/day_one/setup.ts @@ -45,14 +45,12 @@ export const createDayOneDisplay = async (tx: TransactionBlock, network: Network export const createDayOneTransferPolicy = async ( tx: TransactionBlock, - client: SuiClient, network: Network, ) => { - const config = network === 'mainnet' ? mainnetConfig : addressConfig; const mainPackageConfig = mainPackage[network]; - const existingPolicy = await queryTransferPolicy(client, dayOneType(config)); + const existingPolicy = await queryTransferPolicy(mainPackageConfig.client, dayOneType(config)); if (existingPolicy.length > 0) { console.warn(`Type ${dayOneType} already had a tranfer policy so the transaction was skipped.`); From 9a4be7643dd2a3cd7b9111cc614d066ceed782b3 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Mon, 25 Mar 2024 09:21:58 -0400 Subject: [PATCH 06/14] normalize imports --- scripts/airdrop/airdrop-mint.ts | 5 ++--- scripts/airdrop/airdrop-setup.ts | 2 +- scripts/airdrop/authorize-app.ts | 2 +- scripts/airdrop/coins.ts | 2 +- scripts/airdrop/deauthorize-app.ts | 2 +- scripts/airdrop/helper.ts | 7 +++---- scripts/config/discounts.ts | 2 +- scripts/day_one/setup.ts | 3 +-- scripts/register_with_oracle/register_with_oracle.ts | 4 ++-- scripts/reserved-names/transfer-names.ts | 10 +++++++--- scripts/transactions/authorize_utils.ts | 9 ++++++++- .../deauthorize_auction_authorize_registration.ts | 2 +- scripts/transactions/deepbook/create_pools.ts | 2 +- scripts/transactions/display_ipfs_to_google_storage.ts | 3 +-- scripts/transactions/quest3/disable_discounts.ts | 2 +- scripts/transactions/quest3/disable_free_claims.ts | 2 +- scripts/transactions/quest_3_setup.ts | 4 ++-- scripts/transactions/withdraw_funds_20290927.ts | 2 +- 18 files changed, 36 insertions(+), 29 deletions(-) diff --git a/scripts/airdrop/airdrop-mint.ts b/scripts/airdrop/airdrop-mint.ts index 0491c5b1..f456fd3d 100644 --- a/scripts/airdrop/airdrop-mint.ts +++ b/scripts/airdrop/airdrop-mint.ts @@ -1,7 +1,6 @@ // TESTNET VERSION HERE. WILL CLEAN UP. -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { SuiObjectData, SuiObjectRef } from "@mysten/sui.js/client"; -import { SuiTransactionBlockResponse } from "@mysten/sui.js/client"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { SuiObjectData, SuiObjectRef, SuiTransactionBlockResponse } from "@mysten/sui.js/src/client"; import { MAX_MINTS_PER_TRANSACTION, addressesToBuffer, csvToBatches, executeTx, readAddressesFromFile } from './helper'; diff --git a/scripts/airdrop/airdrop-setup.ts b/scripts/airdrop/airdrop-setup.ts index 7ee0419b..579ae186 100644 --- a/scripts/airdrop/airdrop-setup.ts +++ b/scripts/airdrop/airdrop-setup.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { batchToHash, executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { createDayOneDisplay, createDayOneTransferPolicy } from "../day_one/setup"; diff --git a/scripts/airdrop/authorize-app.ts b/scripts/airdrop/authorize-app.ts index 3a712a89..8167828c 100644 --- a/scripts/airdrop/authorize-app.ts +++ b/scripts/airdrop/authorize-app.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { Network, mainPackage } from "../config/constants"; diff --git a/scripts/airdrop/coins.ts b/scripts/airdrop/coins.ts index b62445fa..cafd8a9b 100644 --- a/scripts/airdrop/coins.ts +++ b/scripts/airdrop/coins.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { RawSigner } from "@mysten/sui.js/src/signers/raw-signer"; import {executeTx } from "./helper"; import { AirdropConfig } from "../config/day_one"; diff --git a/scripts/airdrop/deauthorize-app.ts b/scripts/airdrop/deauthorize-app.ts index 749d37a6..c757e4ae 100644 --- a/scripts/airdrop/deauthorize-app.ts +++ b/scripts/airdrop/deauthorize-app.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { Network, mainPackage } from "../config/constants"; diff --git a/scripts/airdrop/helper.ts b/scripts/airdrop/helper.ts index a2c871b3..2a253131 100644 --- a/scripts/airdrop/helper.ts +++ b/scripts/airdrop/helper.ts @@ -1,5 +1,5 @@ -import { TransactionArgument, TransactionBlock } from "@mysten/sui.js/transactions"; -import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519'; +import { TransactionArgument, TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { Ed25519Keypair } from '@mysten/sui.js/src/keypairs/ed25519'; import * as blake2 from 'blake2'; import fs from "fs"; import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one"; @@ -8,7 +8,7 @@ import { execSync } from 'child_process'; import { RawSigner } from "@mysten/sui.js/src/signers/raw-signer"; import { isValidSuiAddress, normalizeSuiAddress, toB64 } from "@mysten/sui.js/src/utils"; import { ExecutionStatus, GasCostSummary, SuiClient, SuiTransactionBlockResponse } from "@mysten/sui.js/src/client"; -import { bcs } from "@mysten/sui.js/bcs"; +import { bcs } from "@mysten/sui.js/src/bcs"; import { SignerWithProvider } from "@mysten/sui.js/src/signers/signer-with-provider"; export const MAX_MINTS_PER_TRANSACTION = 2_000; @@ -170,7 +170,6 @@ export const prepareMultisigTx = async ( tx: TransactionBlock, network: Network ) => { - const config = mainPackage[network]; const gasObjectId = process.env.GAS_OBJECT; diff --git a/scripts/config/discounts.ts b/scripts/config/discounts.ts index f5789324..944b5d12 100644 --- a/scripts/config/discounts.ts +++ b/scripts/config/discounts.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { Network, PackageInfo } from "./constants"; export const SUIFREN_BULLSHARK_TYPE: Record = { diff --git a/scripts/day_one/setup.ts b/scripts/day_one/setup.ts index 84370aca..979e7f1c 100644 --- a/scripts/day_one/setup.ts +++ b/scripts/day_one/setup.ts @@ -1,5 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { SuiClient } from "@mysten/sui.js/client" +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { Network, mainPackage } from "../config/constants"; import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one"; import { createTransferPolicy, queryTransferPolicy } from "@mysten/kiosk"; diff --git a/scripts/register_with_oracle/register_with_oracle.ts b/scripts/register_with_oracle/register_with_oracle.ts index 5a3ed58d..8a0e7aee 100644 --- a/scripts/register_with_oracle/register_with_oracle.ts +++ b/scripts/register_with_oracle/register_with_oracle.ts @@ -2,8 +2,8 @@ import { mainPackage } from "../config/constants"; import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js"; import dotenv from "dotenv"; import { executeTx, prepareSigner } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { SuiClient } from "@mysten/sui.js/client"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { SuiClient } from "@mysten/sui.js/src/client"; dotenv.config(); const setup = async () => { diff --git a/scripts/reserved-names/transfer-names.ts b/scripts/reserved-names/transfer-names.ts index 2995a121..b70eb3bd 100644 --- a/scripts/reserved-names/transfer-names.ts +++ b/scripts/reserved-names/transfer-names.ts @@ -1,6 +1,6 @@ -import { SuiObjectResponse } from "@mysten/sui.js/client"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { isValidSuiAddress } from "@mysten/sui.js/utils"; +import { SuiClient, SuiObjectResponse } from "@mysten/sui.js/src/client"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { isValidSuiAddress } from "@mysten/sui.js/src/utils"; import fs from "fs"; import { prepareMultisigTx } from "../airdrop/helper"; @@ -82,6 +82,10 @@ const prepareTx = () => { txb.transferObjects([...objects.map(x => txb.object(x))], txb.pure(recipient)); } + txb.build({ + client: new SuiClient({url: ''}) + }); + return prepareMultisigTx(txb, 'mainnet'); } diff --git a/scripts/transactions/authorize_utils.ts b/scripts/transactions/authorize_utils.ts index 62a3e822..84300c01 100644 --- a/scripts/transactions/authorize_utils.ts +++ b/scripts/transactions/authorize_utils.ts @@ -4,8 +4,9 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { Network, mainPackage } from "../config/constants"; +import { SuiClient } from "@mysten/sui.js/src/client"; export const authorizeDirectSetupApp = async (network: Network) => { const tx = new TransactionBlock(); @@ -22,6 +23,12 @@ export const authorizeDirectSetupApp = async (network: Network) => { typeArguments: [`${config.directSetupPackageId}::direct_setup::DirectSetup`], }); + tx.build({ + client: new SuiClient({ + url: '' + }) + }) + // for mainnet, we just prepare multisig TX if(network === 'mainnet') return prepareMultisigTx(tx, 'mainnet'); diff --git a/scripts/transactions/deauthorize_auction_authorize_registration.ts b/scripts/transactions/deauthorize_auction_authorize_registration.ts index 04f1e50b..6e7eb367 100644 --- a/scripts/transactions/deauthorize_auction_authorize_registration.ts +++ b/scripts/transactions/deauthorize_auction_authorize_registration.ts @@ -4,7 +4,7 @@ import dotenv from "dotenv"; dotenv.config(); import { prepareMultisigTx } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { mainPackage } from "../config/constants"; const migrateToDirectRegistration = async () => { diff --git a/scripts/transactions/deepbook/create_pools.ts b/scripts/transactions/deepbook/create_pools.ts index fcd70a68..7b34642a 100644 --- a/scripts/transactions/deepbook/create_pools.ts +++ b/scripts/transactions/deepbook/create_pools.ts @@ -9,7 +9,7 @@ import { prepareSigner, } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; const SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"; diff --git a/scripts/transactions/display_ipfs_to_google_storage.ts b/scripts/transactions/display_ipfs_to_google_storage.ts index 82de9f69..2fc0b01b 100644 --- a/scripts/transactions/display_ipfs_to_google_storage.ts +++ b/scripts/transactions/display_ipfs_to_google_storage.ts @@ -4,8 +4,7 @@ import dotenv from "dotenv"; dotenv.config(); import { prepareMultisigTx } from "../airdrop/helper"; -import { authorizeBogoApp } from "../airdrop/authorize-app"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { mainPackage } from "../config/constants"; const run = async () => { diff --git a/scripts/transactions/quest3/disable_discounts.ts b/scripts/transactions/quest3/disable_discounts.ts index 6b923df2..fa742abd 100644 --- a/scripts/transactions/quest3/disable_discounts.ts +++ b/scripts/transactions/quest3/disable_discounts.ts @@ -5,7 +5,7 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { DAY_ONE_TYPE, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeDiscountForType } from "../../config/discounts"; const execute = async (network: Network) => { diff --git a/scripts/transactions/quest3/disable_free_claims.ts b/scripts/transactions/quest3/disable_free_claims.ts index 916c648a..73ef3ee4 100644 --- a/scripts/transactions/quest3/disable_free_claims.ts +++ b/scripts/transactions/quest3/disable_free_claims.ts @@ -5,7 +5,7 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { DAY_ONE_TYPE, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeFreeClaimsForType, setupDiscountForType } from "../../config/discounts"; // Setup Quests 3. diff --git a/scripts/transactions/quest_3_setup.ts b/scripts/transactions/quest_3_setup.ts index 8189492c..8efbfccf 100644 --- a/scripts/transactions/quest_3_setup.ts +++ b/scripts/transactions/quest_3_setup.ts @@ -5,8 +5,8 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../airdrop/helper"; import { Network, PackageInfo, mainPackage } from "../config/constants"; -import { MIST_PER_SUI } from '@mysten/sui.js/utils'; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { MIST_PER_SUI } from '@mysten/sui.js/src/utils'; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { DAY_ONE_TYPE, Discount, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeDiscountForType, setupDiscountForType } from "../config/discounts"; // Setup Quests 3. diff --git a/scripts/transactions/withdraw_funds_20290927.ts b/scripts/transactions/withdraw_funds_20290927.ts index 74e737c7..c61223aa 100644 --- a/scripts/transactions/withdraw_funds_20290927.ts +++ b/scripts/transactions/withdraw_funds_20290927.ts @@ -1,7 +1,7 @@ // Copyright (c) 2023, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionBlock } from "@mysten/sui.js/src/transactions"; import { mainPackage } from '../config/constants'; import { prepareMultisigTx } from '../airdrop/helper'; From c9a0fda4842ec206c8fadf2cc38eefd0dc190b6d Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Mon, 25 Mar 2024 11:41:43 -0400 Subject: [PATCH 07/14] remove /src --- scripts/airdrop/airdrop-mint.ts | 30 ++++---- scripts/airdrop/airdrop-setup.ts | 5 +- scripts/airdrop/authorize-app.ts | 5 +- scripts/airdrop/coins.ts | 13 ++-- scripts/airdrop/deauthorize-app.ts | 5 +- scripts/airdrop/helper.ts | 71 +++++++++---------- scripts/config/constants.ts | 4 +- scripts/config/discounts.ts | 2 +- scripts/day_one/setup.ts | 2 +- scripts/pnpm-lock.yaml | 6 +- .../register_with_oracle.ts | 6 +- scripts/reserved-names/transfer-names.ts | 6 +- scripts/transactions/authorize_utils.ts | 6 +- ...uthorize_auction_authorize_registration.ts | 2 +- scripts/transactions/deepbook/create_pools.ts | 4 +- .../display_ipfs_to_google_storage.ts | 2 +- .../transactions/quest3/disable_discounts.ts | 4 +- .../quest3/disable_free_claims.ts | 4 +- scripts/transactions/quest_3_setup.ts | 6 +- .../transactions/withdraw_funds_20290927.ts | 2 +- 20 files changed, 88 insertions(+), 97 deletions(-) diff --git a/scripts/airdrop/airdrop-mint.ts b/scripts/airdrop/airdrop-mint.ts index f456fd3d..7b063311 100644 --- a/scripts/airdrop/airdrop-mint.ts +++ b/scripts/airdrop/airdrop-mint.ts @@ -1,18 +1,18 @@ // TESTNET VERSION HERE. WILL CLEAN UP. -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; -import { SuiObjectData, SuiObjectRef, SuiTransactionBlockResponse } from "@mysten/sui.js/src/client"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { SuiClient, SuiObjectData, SuiObjectRef, SuiTransactionBlockResponse } from "@mysten/sui.js/client"; import { MAX_MINTS_PER_TRANSACTION, addressesToBuffer, csvToBatches, executeTx, readAddressesFromFile } from './helper'; import { prepareSigner } from "./helper"; import { addressConfig } from "../config/day_one"; -import { mainPackage } from "../config/constants"; +import { Network, PackageInfo, mainPackage } from "../config/constants"; const SUI_COIN_TYPE = '0x2::coin::Coin<0x2::sui::SUI>'; const network = 'testnet' // change to mainnet when running it. -const signer = prepareSigner(mainPackage[network].client); +const signer = prepareSigner(); const config = addressConfig; const usedCoinObjects = new Set(); @@ -24,11 +24,11 @@ const millisToMinutesAndSeconds = (millis: number) => { } /* get X amount of chunks of Coins based on amount per tx. */ -const prepareCoinObjects = async (chunks: number) => { +const prepareCoinObjects = async (chunks: number, client: SuiClient) => { const tx = new TransactionBlock(); // get the base gas coin from the provider - const { data } = await signer.client.getObject({ + const { data } = await client.getObject({ id: config.baseCoinObjectId }); @@ -50,7 +50,7 @@ const prepareCoinObjects = async (chunks: number) => { } tx.transferObjects(coinsSplitted, tx.pure(config.massMintingAddress, 'address')); - const res = await executeTx(signer, tx); + const res = await executeTx(signer, tx, mainPackage[network].client); //@ts-ignore return res?.objectChanges?.filter(x => x.type === 'created' && x.objectType === SUI_COIN_TYPE).map((x: SuiObjectData) => ( @@ -65,7 +65,8 @@ const prepareCoinObjects = async (chunks: number) => { /** * Mints a batch of bullsharks. * */ -const mintDayOne = async ({ +const mintDayOne = async (client: SuiClient, + { id, batch, coinObject, @@ -98,7 +99,7 @@ const mintDayOne = async ({ tx.setGasBudget(2_900_000_000); - let res = await executeTx(signer, tx, { + let res = await executeTx(signer, tx, client, { isAirdropExecution: true, chunkNum: id, failedChunks @@ -107,7 +108,7 @@ const mintDayOne = async ({ return getExecutionStatusType(res as SuiTransactionBlockResponse) === 'success'; } -const executeMintsForBatches = async (batches: string[][], initialBatch = 0) => { +const executeMintsForBatches = async (batches: string[][], initialBatch = 0, network: Network) => { const MAX_BATCH_SIZE = 50; // The current airdrop is doable in 48 hashes. 50 batches will be running concurrently. let start = Date.now(); // time we started the mint process. @@ -116,11 +117,13 @@ const executeMintsForBatches = async (batches: string[][], initialBatch = 0) => let success = 0; let fail = 0; const failedChunks: number[] = []; + let config = mainPackage[network]; while (currentSliceStart < batches.length) { const batchToExecute = batches.slice(currentSliceStart, currentSliceStart + MAX_BATCH_SIZE); const results = await executeConcurrently( + config, batchToExecute, { sliceStart: currentSliceStart, @@ -152,12 +155,12 @@ const executeMintsForBatches = async (batches: string[][], initialBatch = 0) => } -const executeConcurrently = async (slicedBatches: string[][], options: { +const executeConcurrently = async (config: PackageInfo, slicedBatches: string[][], options: { sliceStart: number; failedChunks: number[]; }) => { - const coins = await prepareCoinObjects(slicedBatches.length + 1); // does the splitting of coins with some extra space. + const coins = await prepareCoinObjects(slicedBatches.length + 1, config.client); // does the splitting of coins with some extra space. if (!coins) { console.error("Failed to prepare coins on slice: " + options.sliceStart); @@ -166,7 +169,8 @@ const executeConcurrently = async (slicedBatches: string[][], options: { return await Promise.all( slicedBatches.map((slice, index) => - mintDayOne({ + mintDayOne(config.client, + { id: options.sliceStart + index, batch: slice, coinObject: coins[index], diff --git a/scripts/airdrop/airdrop-setup.ts b/scripts/airdrop/airdrop-setup.ts index 579ae186..754d9e62 100644 --- a/scripts/airdrop/airdrop-setup.ts +++ b/scripts/airdrop/airdrop-setup.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { batchToHash, executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { createDayOneDisplay, createDayOneTransferPolicy } from "../day_one/setup"; @@ -40,8 +40,7 @@ export const setupAirdrop = async (batches: string[][], network: Network): Promi // return if we're on multisig execution. if(airdropConfig.isMainnet) return tx; - const signer = prepareSigner(mainPackage[network].client); - await executeTx(signer, tx); + await executeTx(prepareSigner(), tx, mainPackage[network].client); } diff --git a/scripts/airdrop/authorize-app.ts b/scripts/airdrop/authorize-app.ts index 8167828c..695c27d7 100644 --- a/scripts/airdrop/authorize-app.ts +++ b/scripts/airdrop/authorize-app.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { Network, mainPackage } from "../config/constants"; @@ -21,8 +21,7 @@ export const authorizeBogoApp = async (network: Network): Promise { +export const cleanUpCoins = async (signer: Ed25519Keypair, config: AirdropConfig, client: SuiClient) => { let hasNextPage = true; let cursor = undefined; let coins = []; while (hasNextPage) { - const data = await signer.client.getAllCoins({ + const data = await client.getAllCoins({ owner: config.massMintingAddress, cursor, limit: 50 @@ -33,7 +34,7 @@ export const cleanUpCoins = async (signer: RawSigner, config: AirdropConfig) => while (count > 1) { // get the base gas coin from the provider - const { data } = await signer.client.getObject({ + const { data } = await client.getObject({ id: config.baseCoinObjectId }); @@ -64,7 +65,7 @@ export const cleanUpCoins = async (signer: RawSigner, config: AirdropConfig) => })) ]); - const res = await executeTx(signer, tx); + const res = await executeTx(signer, tx, client); if(res) count = count - mergeAbleCoins.length -1; } } diff --git a/scripts/airdrop/deauthorize-app.ts b/scripts/airdrop/deauthorize-app.ts index c757e4ae..1419916c 100644 --- a/scripts/airdrop/deauthorize-app.ts +++ b/scripts/airdrop/deauthorize-app.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { executeTx, prepareSigner } from "./helper"; import { addressConfig, mainnetConfig } from "../config/day_one"; import { Network, mainPackage } from "../config/constants"; @@ -21,8 +21,7 @@ export const deauthorizeBogoApp = async (network: Network): Promise { - console.dir(e, { depth: null }); - if (!options) { - console.log(e); - return false; + return client.signAndExecuteTransactionBlock({ + transactionBlock: tx, + signer: keypair, + options: requestOptions + }).then(function(res) { + if (options?.isAirdropExecution) { + if (getExecutionStatus(res)?.status === 'success') console.log(`Success of chunk: ${options?.chunkNum}`); + else { + options.failedChunks.push(options?.chunkNum); + console.log(`Failure of chunk: ${options?.chunkNum}`); } - options.failedChunks.push(options.chunkNum); + } else { + console.dir(res) + console.log(getExecutionStatus(res)); + console.log(getExecutionStatusGasSummary(res)); + } + }).catch (e => { + console.dir(e, { depth: null }); + if (!options) { console.log(e); - console.log(`Failure of chunk: ${options?.chunkNum}`); return false; - }); + } + options.failedChunks.push(options.chunkNum); + console.log(e); + console.log(`Failure of chunk: ${options?.chunkNum}`); + return false; + }) } @@ -125,12 +120,10 @@ export const batchToHash = (batch: string[]) => { } -export const prepareSigner = (client: SuiClient): RawSigner => { +export const prepareSigner = (): Ed25519Keypair => { const phrase = process.env.ADMIN_PHRASE || ''; if (!phrase) throw new Error(`ERROR: Admin mnemonic is not exported! Please run 'export ADMIN_PHRASE=""'`); - const keypair = Ed25519Keypair.deriveKeypair(phrase!); - - return new RawSigner(keypair, client); + return Ed25519Keypair.deriveKeypair(phrase!); } // converts an array of addresses to a buffer using the `buffer` module. diff --git a/scripts/config/constants.ts b/scripts/config/constants.ts index 1230f7da..0717010f 100644 --- a/scripts/config/constants.ts +++ b/scripts/config/constants.ts @@ -1,5 +1,5 @@ -import { SuiClient } from "@mysten/sui.js/src/client"; -import { normalizeSuiAddress } from "@mysten/sui.js/src/utils"; +import { SuiClient } from "@mysten/sui.js/client"; +import { normalizeSuiAddress } from "@mysten/sui.js/utils"; export type Network = 'mainnet' | 'testnet' diff --git a/scripts/config/discounts.ts b/scripts/config/discounts.ts index 944b5d12..f5789324 100644 --- a/scripts/config/discounts.ts +++ b/scripts/config/discounts.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, PackageInfo } from "./constants"; export const SUIFREN_BULLSHARK_TYPE: Record = { diff --git a/scripts/day_one/setup.ts b/scripts/day_one/setup.ts index 979e7f1c..d57e9c44 100644 --- a/scripts/day_one/setup.ts +++ b/scripts/day_one/setup.ts @@ -1,4 +1,4 @@ -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, mainPackage } from "../config/constants"; import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one"; import { createTransferPolicy, queryTransferPolicy } from "@mysten/kiosk"; diff --git a/scripts/pnpm-lock.yaml b/scripts/pnpm-lock.yaml index f59bcd5f..2727ece2 100644 --- a/scripts/pnpm-lock.yaml +++ b/scripts/pnpm-lock.yaml @@ -194,10 +194,6 @@ packages: - utf-8-validate dev: false - /@scure/base@1.1.1: - resolution: {integrity: sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==} - dev: false - /@scure/base@1.1.6: resolution: {integrity: sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g==} dev: false @@ -214,7 +210,7 @@ packages: resolution: {integrity: sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==} dependencies: '@noble/hashes': 1.3.1 - '@scure/base': 1.1.1 + '@scure/base': 1.1.6 dev: false /@suchipi/femver@1.0.0: diff --git a/scripts/register_with_oracle/register_with_oracle.ts b/scripts/register_with_oracle/register_with_oracle.ts index 8a0e7aee..15211f64 100644 --- a/scripts/register_with_oracle/register_with_oracle.ts +++ b/scripts/register_with_oracle/register_with_oracle.ts @@ -2,8 +2,8 @@ import { mainPackage } from "../config/constants"; import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js"; import dotenv from "dotenv"; import { executeTx, prepareSigner } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; -import { SuiClient } from "@mysten/sui.js/src/client"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { SuiClient } from "@mysten/sui.js/client"; dotenv.config(); const setup = async () => { @@ -44,7 +44,7 @@ const setup = async () => { }); txb.transferObjects([nft], txb.pure.address('insert_address')) // send to tx sender - return executeTx(prepareSigner(setup.client), txb); + return executeTx(prepareSigner(), txb, setup.client); }; setup(); \ No newline at end of file diff --git a/scripts/reserved-names/transfer-names.ts b/scripts/reserved-names/transfer-names.ts index b70eb3bd..87d4cbc1 100644 --- a/scripts/reserved-names/transfer-names.ts +++ b/scripts/reserved-names/transfer-names.ts @@ -1,6 +1,6 @@ -import { SuiClient, SuiObjectResponse } from "@mysten/sui.js/src/client"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; -import { isValidSuiAddress } from "@mysten/sui.js/src/utils"; +import { SuiClient, SuiObjectResponse } from "@mysten/sui.js/client"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { isValidSuiAddress } from "@mysten/sui.js/utils"; import fs from "fs"; import { prepareMultisigTx } from "../airdrop/helper"; diff --git a/scripts/transactions/authorize_utils.ts b/scripts/transactions/authorize_utils.ts index 84300c01..b84fb87d 100644 --- a/scripts/transactions/authorize_utils.ts +++ b/scripts/transactions/authorize_utils.ts @@ -4,9 +4,9 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, mainPackage } from "../config/constants"; -import { SuiClient } from "@mysten/sui.js/src/client"; +import { SuiClient } from "@mysten/sui.js/client"; export const authorizeDirectSetupApp = async (network: Network) => { const tx = new TransactionBlock(); @@ -32,7 +32,7 @@ export const authorizeDirectSetupApp = async (network: Network) => { // for mainnet, we just prepare multisig TX if(network === 'mainnet') return prepareMultisigTx(tx, 'mainnet'); - return executeTx(prepareSigner(config.client), tx); + return executeTx(prepareSigner(), tx, config.client); // prepare tx data. } diff --git a/scripts/transactions/deauthorize_auction_authorize_registration.ts b/scripts/transactions/deauthorize_auction_authorize_registration.ts index 6e7eb367..04f1e50b 100644 --- a/scripts/transactions/deauthorize_auction_authorize_registration.ts +++ b/scripts/transactions/deauthorize_auction_authorize_registration.ts @@ -4,7 +4,7 @@ import dotenv from "dotenv"; dotenv.config(); import { prepareMultisigTx } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { mainPackage } from "../config/constants"; const migrateToDirectRegistration = async () => { diff --git a/scripts/transactions/deepbook/create_pools.ts b/scripts/transactions/deepbook/create_pools.ts index bbda5e95..1ef3ecdf 100644 --- a/scripts/transactions/deepbook/create_pools.ts +++ b/scripts/transactions/deepbook/create_pools.ts @@ -9,7 +9,7 @@ import { prepareSigner, } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; const SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"; @@ -123,7 +123,7 @@ const setup = async (network: Network) => { if (network === "mainnet") return prepareMultisigTx(txb, "mainnet"); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.client), txb); + return executeTx(prepareSigner(), txb, setup.client); }; if (process.env.NETWORK === "mainnet") setup("mainnet"); diff --git a/scripts/transactions/display_ipfs_to_google_storage.ts b/scripts/transactions/display_ipfs_to_google_storage.ts index 2fc0b01b..8a22c6b0 100644 --- a/scripts/transactions/display_ipfs_to_google_storage.ts +++ b/scripts/transactions/display_ipfs_to_google_storage.ts @@ -4,7 +4,7 @@ import dotenv from "dotenv"; dotenv.config(); import { prepareMultisigTx } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { mainPackage } from "../config/constants"; const run = async () => { diff --git a/scripts/transactions/quest3/disable_discounts.ts b/scripts/transactions/quest3/disable_discounts.ts index fa742abd..f1dcf0fa 100644 --- a/scripts/transactions/quest3/disable_discounts.ts +++ b/scripts/transactions/quest3/disable_discounts.ts @@ -5,7 +5,7 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { DAY_ONE_TYPE, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeDiscountForType } from "../../config/discounts"; const execute = async (network: Network) => { @@ -21,7 +21,7 @@ const execute = async (network: Network) => { if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.client), txb); + return executeTx(prepareSigner(), txb, setup.client); } if(process.env.NETWORK === 'mainnet') execute('mainnet') diff --git a/scripts/transactions/quest3/disable_free_claims.ts b/scripts/transactions/quest3/disable_free_claims.ts index 73ef3ee4..1fd8aab7 100644 --- a/scripts/transactions/quest3/disable_free_claims.ts +++ b/scripts/transactions/quest3/disable_free_claims.ts @@ -5,7 +5,7 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../../airdrop/helper"; import { Network, mainPackage } from "../../config/constants"; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { DAY_ONE_TYPE, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeFreeClaimsForType, setupDiscountForType } from "../../config/discounts"; // Setup Quests 3. @@ -22,7 +22,7 @@ const setup = async (network: Network) => { if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.client), txb); + return executeTx(prepareSigner(), txb, setup.client); } if(process.env.NETWORK === 'mainnet') setup('mainnet') diff --git a/scripts/transactions/quest_3_setup.ts b/scripts/transactions/quest_3_setup.ts index 8efbfccf..fc8305b0 100644 --- a/scripts/transactions/quest_3_setup.ts +++ b/scripts/transactions/quest_3_setup.ts @@ -5,8 +5,8 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../airdrop/helper"; import { Network, PackageInfo, mainPackage } from "../config/constants"; -import { MIST_PER_SUI } from '@mysten/sui.js/src/utils'; -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { MIST_PER_SUI } from '@mysten/sui.js/utils'; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { DAY_ONE_TYPE, Discount, SUIFREN_BULLSHARK_TYPE, SUIFREN_CAPY_TYPE, removeDiscountForType, setupDiscountForType } from "../config/discounts"; // Setup Quests 3. @@ -52,7 +52,7 @@ const setup = async (network: Network) => { if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); // For testnet, we execute the TX directly. - return executeTx(prepareSigner(setup.client), txb); + return executeTx(prepareSigner(), txb, setup.client); } if(process.env.NETWORK === 'mainnet') setup('mainnet') diff --git a/scripts/transactions/withdraw_funds_20290927.ts b/scripts/transactions/withdraw_funds_20290927.ts index c61223aa..74e737c7 100644 --- a/scripts/transactions/withdraw_funds_20290927.ts +++ b/scripts/transactions/withdraw_funds_20290927.ts @@ -1,7 +1,7 @@ // Copyright (c) 2023, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { TransactionBlock } from "@mysten/sui.js/src/transactions"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; import { mainPackage } from '../config/constants'; import { prepareMultisigTx } from '../airdrop/helper'; From 7e26946a0469ee953a4e8383e89161744003e9a1 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Mon, 25 Mar 2024 18:24:43 -0400 Subject: [PATCH 08/14] remove oracle changes --- packages/registration/Move.lock | 22 +-- packages/registration/Move.toml | 1 - packages/registration/sources/register.move | 56 +----- .../registration/tests/register_tests.move | 179 ++---------------- 4 files changed, 25 insertions(+), 233 deletions(-) diff --git a/packages/registration/Move.lock b/packages/registration/Move.lock index c948e134..9e1d8db2 100644 --- a/packages/registration/Move.lock +++ b/packages/registration/Move.lock @@ -2,11 +2,10 @@ [move] version = 0 -manifest_digest = "714124D2EC7F60B1BD3D39D85C3FDC9F6B1043B5ADFFAC92D5C7AE3C42F6BB18" -deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +manifest_digest = "75434D5374AE0B76DFC7B2C8B1D93D92E43B7C10C03782CF67925E35F379A78A" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" dependencies = [ - { name = "Pyth" }, { name = "Sui" }, { name = "suins" }, ] @@ -15,15 +14,6 @@ dependencies = [ name = "MoveStdlib" source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } -[[move.package]] -name = "Pyth" -source = { git = "https://github.com/0xaslan/pyth-crosschain.git", rev = "sui/price-info-test", subdir = "target_chains/sui/contracts" } - -dependencies = [ - { name = "Sui" }, - { name = "Wormhole" }, -] - [[move.package]] name = "Sui" source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } @@ -32,14 +22,6 @@ dependencies = [ { name = "MoveStdlib" }, ] -[[move.package]] -name = "Wormhole" -source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "82d82bffd5a8566e4b5d94be4e4678ad55ab1f4f", subdir = "sui/wormhole" } - -dependencies = [ - { name = "Sui" }, -] - [[move.package]] name = "suins" source = { local = "../suins" } diff --git a/packages/registration/Move.toml b/packages/registration/Move.toml index 51dd10e2..628138c6 100644 --- a/packages/registration/Move.toml +++ b/packages/registration/Move.toml @@ -5,7 +5,6 @@ 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" } -Pyth = {git = "https://github.com/0xaslan/pyth-crosschain.git", subdir = "target_chains/sui/contracts", rev = "sui/price-info-test"} [addresses] registration = "0x0" diff --git a/packages/registration/sources/register.move b/packages/registration/sources/register.move index 41a6a94e..ffe15345 100644 --- a/packages/registration/sources/register.move +++ b/packages/registration/sources/register.move @@ -4,7 +4,6 @@ module registration::register { use std::string::{Self, String}; use sui::coin::{Self, Coin}; - use sui::math; use sui::tx_context::TxContext; use sui::clock::Clock; use sui::sui::SUI; @@ -15,24 +14,11 @@ module registration::register { use suins::config::{Self, Config}; use suins::suins_registration::SuinsRegistration; - use pyth::price_feed::{Self, PriceFeed}; - use pyth::price_info::{Self, PriceInfoObject, PriceInfo}; - use pyth::price_identifier::{Self}; - use pyth::price; - use pyth::i64; - /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; /// Trying to register a subdomain (only *.sui is currently allowed). /// The payment does not match the price for the domain. const EIncorrectAmount: u64 = 4; - /// Pyth oracle reports a precision that's too high. - const EIncorrectPrecision: u64 = 5; - /// Incorrect price feed ID - const EIncorrectPriceFeedID: u64 = 6; - /// Sui Price Feed ID - const SUI_PRICE_FEED_MAINNET_ID: vector = x"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"; - const SUI_PRICE_FEED_TESTNET_ID: vector = x"50c67b3fd225db8912a424dd4baed60ffdde625ed2feaaf283724f9608fea266"; /// Authorization token for the app. struct Register has drop {} @@ -49,7 +35,6 @@ module registration::register { domain_name: String, no_years: u8, payment: Coin, - price_info_object: &PriceInfoObject, clock: &Clock, ctx: &mut TxContext ): SuinsRegistration { @@ -62,48 +47,13 @@ module registration::register { assert!(0 < no_years && no_years <= 5, EInvalidYearsArgument); - let price_info = &price_info::get_price_info_from_price_info_object(price_info_object); - validate_sui_price_feed(price_info); - let label = domain::sld(&domain); - let price_feed = price_info::get_price_feed(price_info); - let (sui_value_in_usd_lower_bound, sui_value_in_usd_upper_bound) = calculate_lower_upper_price(price_feed, coin::value(&payment)); - let price_in_usd = config::calculate_price(config, (string::length(label) as u8), no_years); + let price = config::calculate_price(config, (string::length(label) as u8), no_years); - assert!(sui_value_in_usd_lower_bound <= price_in_usd, EIncorrectAmount); - assert!(sui_value_in_usd_upper_bound >= price_in_usd, EIncorrectAmount); + assert!(coin::value(&payment) == price, EIncorrectAmount); suins::app_add_balance(Register {}, suins, coin::into_balance(payment)); let registry = suins::app_registry_mut(Register {}, suins); registry::add_record(registry, domain, no_years, clock, ctx) } - - fun validate_sui_price_feed( - price_info: &PriceInfo - ) { - let price_identifier = &price_info::get_price_identifier(price_info); - let price_id_bytes = price_identifier::get_bytes(price_identifier); - assert!(price_id_bytes == SUI_PRICE_FEED_MAINNET_ID || price_id_bytes == SUI_PRICE_FEED_TESTNET_ID, EIncorrectPriceFeedID); - } - - fun calculate_lower_upper_price( - price_feed: &PriceFeed, - sui_quantity: u64 - ): (u64, u64) { - // https://docs.pyth.network/price-feeds/pythnet-price-feeds/best-practices - let sui_price = &price_feed::get_price(price_feed); - let sui_price_i64 = &price::get_price(sui_price); - let sui_price_u64 = i64::get_magnitude_if_positive(sui_price_i64); - let sui_price_lower_bound = sui_price_u64 - price::get_conf(sui_price); - let sui_price_upper_bound = sui_price_u64 + price::get_conf(sui_price); - let exponent_i64 = &price::get_expo(sui_price); - let exponent_u64 = i64::get_magnitude_if_negative(exponent_i64); - assert!(exponent_u64 < 256, EIncorrectPrecision); - let exponent_u8 = (exponent_u64 as u8); - - let sui_value_in_usd_lower_bound = sui_quantity * sui_price_lower_bound / (math::pow(10, exponent_u8)); - let sui_value_in_usd_upper_bound = sui_quantity * sui_price_upper_bound / (math::pow(10, exponent_u8)); - - (sui_value_in_usd_lower_bound, sui_value_in_usd_upper_bound) - } -} +} \ No newline at end of file diff --git a/packages/registration/tests/register_tests.move b/packages/registration/tests/register_tests.move index 0e417ce2..a365b9ca 100644 --- a/packages/registration/tests/register_tests.move +++ b/packages/registration/tests/register_tests.move @@ -22,12 +22,6 @@ module registration::register_tests { use suins::auction_tests; use suins::auction::{Self, App as AuctionApp}; - use pyth::price_identifier; - use pyth::price_feed; - use pyth::price_info::{Self, PriceInfoObject}; - use pyth::price; - use pyth::i64; - const SUINS_ADDRESS: address = @0xA001; const AUCTIONED_DOMAIN_NAME: vector = b"tes-t2.sui"; const DOMAIN_NAME: vector = b"abc.sui"; @@ -56,26 +50,11 @@ module registration::register_tests { scenario_val } - public fun oracle_util( - desired_price_6_decimals: u64, - scenario: &mut Scenario - ): PriceInfoObject { - let price_identifier = price_identifier::from_byte_vec(x"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744"); - let price_i64 = i64::new(desired_price_6_decimals, false); // ie: 1.610000 - let expo_i64 = i64::new(6, true); // 10^-6 - let price = price::new(price_i64, 10000, expo_i64, 0); // confidence is 1 cent - let ema_price = copy(price); - let price_feed = price_feed::new(price_identifier, price, ema_price); - let price_info = price_info::new_price_info(0, 0, price_feed); - price_info::new_test_price_info_object(price_info, ctx(scenario)) - } - public fun register_util( scenario: &mut Scenario, domain_name: String, no_years: u8, amount: u64, - price_info: &PriceInfoObject, clock_tick: u64 ): SuinsRegistration { test_scenario::next_tx(scenario, SUINS_ADDRESS); @@ -84,7 +63,7 @@ module registration::register_tests { let clock = test_scenario::take_shared(scenario); clock::increment_for_testing(&mut clock, clock_tick); - let nft = register(&mut suins, domain_name, no_years, payment, price_info, &clock, ctx(scenario)); + let nft = register(&mut suins, domain_name, no_years, payment, &clock, ctx(scenario)); test_scenario::return_shared(clock); test_scenario::return_shared(suins); @@ -114,64 +93,25 @@ module registration::register_tests { fun test_register() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); // $1 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), &price_info_object, 20); + let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), 20); assert_balance(scenario, 1600 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), &price_info_object, 30); + let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), 30); assert_balance(scenario, 1750 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); - test_scenario::end(scenario_val); - } - - #[test] - fun test_register_oracle() { - let scenario_val = test_init(); - let scenario = &mut scenario_val; - let price_info_object = oracle_util(5000000, scenario); // $5 - - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 240 * mist_per_sui(), &price_info_object, 10); - assert_balance(scenario, 240 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); - - let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 80 * mist_per_sui(), &price_info_object, 20); - assert_balance(scenario, 320 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); - suins_registration::burn_for_testing(nft); - - let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 30 * mist_per_sui(), &price_info_object, 30); - assert_balance(scenario, 350 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); - suins_registration::burn_for_testing(nft); - - price_info::destroy(price_info_object); - let price_info_object = oracle_util(500000, scenario); // $0.5 - - let nft = register_util(scenario, utf8(b"abce-f123.sui"), 3, 300 * mist_per_sui(), &price_info_object, 30); - assert_balance(scenario, 650 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f123.sui")), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 90, 0); - suins_registration::burn_for_testing(nft); - - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -179,12 +119,10 @@ module registration::register_tests { fun test_register_if_not_sui_tld() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -192,12 +130,10 @@ module registration::register_tests { fun test_register_if_incorrect_amount() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1220 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1210 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -205,38 +141,10 @@ module registration::register_tests { fun test_register_if_incorrect_amount_2() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), &price_info_object, 10); - suins_registration::burn_for_testing(nft); - - price_info::destroy(price_info_object); - test_scenario::end(scenario_val); - } - - #[test, expected_failure(abort_code = register::EIncorrectAmount)] - fun test_register_if_incorrect_amount_with_oracle_too_few() { - let scenario_val = test_init(); - let scenario = &mut scenario_val; - let price_info_object = oracle_util(1500000, scenario); // $1.50 - - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 150 * mist_per_sui(), &price_info_object, 10); - suins_registration::burn_for_testing(nft); - - price_info::destroy(price_info_object); - test_scenario::end(scenario_val); - } - - #[test, expected_failure(abort_code = register::EIncorrectAmount)] - fun test_register_if_incorrect_amount_with_oracle_too_much() { - let scenario_val = test_init(); - let scenario = &mut scenario_val; - let price_info_object = oracle_util(1500000, scenario); // $1.50 - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 250 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -244,12 +152,10 @@ module registration::register_tests { fun test_register_if_no_years_more_than_5_years() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -257,33 +163,10 @@ module registration::register_tests { fun test_register_if_no_years_is_zero() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - - let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), &price_info_object, 10); - suins_registration::burn_for_testing(nft); - - price_info::destroy(price_info_object); - test_scenario::end(scenario_val); - } - - #[test, expected_failure(abort_code = register::EIncorrectPriceFeedID)] - fun test_register_incorrect_feed_id() { - let scenario_val = test_init(); - let scenario = &mut scenario_val; - - let price_identifier = price_identifier::from_byte_vec(x"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"); - let price_i64 = i64::new(1000000, false); // ie: 1.610000 - let expo_i64 = i64::new(6, true); // 10^-6 - let price = price::new(price_i64, 10000, expo_i64, 0); // confidence is 1 cent - let ema_price = copy(price); - let price_feed = price_feed::new(price_identifier, price, ema_price); - let price_info = price_info::new_price_info(0, 0, price_feed); - let price_info_object = price_info::new_test_price_info_object(price_info, ctx(scenario)); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 3, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -291,9 +174,8 @@ module registration::register_tests { fun test_register_if_expired() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); @@ -304,7 +186,6 @@ module registration::register_tests { utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), - &price_info_object, year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 2400 * mist_per_sui()); @@ -315,7 +196,6 @@ module registration::register_tests { ); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -323,18 +203,16 @@ module registration::register_tests { fun test_register_if_not_expired() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); suins_registration::burn_for_testing(nft); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 20); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 20); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -342,12 +220,10 @@ module registration::register_tests { fun test_register_if_domain_name_starts_with_dash() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -355,12 +231,10 @@ module registration::register_tests { fun test_register_if_domain_name_ends_with_dash() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -368,12 +242,10 @@ module registration::register_tests { fun test_register_if_domain_name_contains_uppercase_character() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -381,12 +253,10 @@ module registration::register_tests { fun test_register_if_domain_name_too_short() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -394,12 +264,10 @@ module registration::register_tests { fun test_register_if_domain_name_contains_subdomain() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); - let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -408,13 +276,11 @@ module registration::register_tests { let scenario_val = test_init(); let scenario = &mut scenario_val; auction::init_for_testing(ctx(scenario)); - let price_info_object = oracle_util(1000000, scenario); auction_tests::normal_auction_flow(scenario); - let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -423,7 +289,6 @@ module registration::register_tests { let scenario_val = test_init(); let scenario = &mut scenario_val; auction::init_for_testing(ctx(scenario)); - let price_info_object = oracle_util(1000000, scenario); auction_tests::normal_auction_flow(scenario); let nft = register_util( @@ -431,14 +296,12 @@ module registration::register_tests { utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), - &price_info_object, year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 50 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(AUCTIONED_DOMAIN_NAME)), 0); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } @@ -446,13 +309,11 @@ module registration::register_tests { fun test_register_aborts_if_register_is_deauthorized() { let scenario_val = test_init(); let scenario = &mut scenario_val; - let price_info_object = oracle_util(1000000, scenario); deauthorize_app_util(scenario); - let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), &price_info_object, 10); + let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); suins_registration::burn_for_testing(nft); - price_info::destroy(price_info_object); test_scenario::end(scenario_val); } -} +} \ No newline at end of file From f4a4fee30192bbf5b524cd1f2a678ea368ba7221 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Wed, 27 Mar 2024 11:38:01 -0400 Subject: [PATCH 09/14] update kiosk client --- scripts/day_one/setup.ts | 42 +++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/scripts/day_one/setup.ts b/scripts/day_one/setup.ts index d57e9c44..3a01c112 100644 --- a/scripts/day_one/setup.ts +++ b/scripts/day_one/setup.ts @@ -1,15 +1,14 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; +import { TransactionArgument, TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, mainPackage } from "../config/constants"; import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one"; -import { createTransferPolicy, queryTransferPolicy } from "@mysten/kiosk"; +import { Network as KioskNetwork, ObjectArgument } from "@mysten/kiosk"; +import { KioskClient } from '@mysten/kiosk'; export const dayOneType = (config: AirdropConfig) => `${config.packageId}::day_one::DayOne`; export const createDayOneDisplay = async (tx: TransactionBlock, network: Network) => { - const config = network === 'mainnet' ? mainnetConfig : addressConfig; - const displayObject = { keys: ["name", "description", "link", "image_url"], values: [ @@ -39,7 +38,6 @@ export const createDayOneDisplay = async (tx: TransactionBlock, network: Network }); tx.transferObjects([display], tx.pure(mainPackageConfig.adminAddress)); - }; export const createDayOneTransferPolicy = async ( @@ -47,19 +45,45 @@ export const createDayOneTransferPolicy = async ( network: Network, ) => { const config = network === 'mainnet' ? mainnetConfig : addressConfig; - const mainPackageConfig = mainPackage[network]; - const existingPolicy = await queryTransferPolicy(mainPackageConfig.client, dayOneType(config)); + + const kioskClient = new KioskClient({ + client: mainPackageConfig.client, + network: network === 'mainnet' ? KioskNetwork.MAINNET : KioskNetwork.TESTNET + }) + + const existingPolicy = await kioskClient.getTransferPolicies({ type: dayOneType(config) }); if (existingPolicy.length > 0) { console.warn(`Type ${dayOneType} already had a tranfer policy so the transaction was skipped.`); return false; } // create transfer policy - let transferPolicyCap = createTransferPolicy(tx, dayOneType(config), config.publisher); + let transferPolicyCap = createTransferPolicy(tx, dayOneType(config), config.publisher) as TransactionArgument; // transfer cap to owner - tx.transferObjects([transferPolicyCap], tx.pure(mainPackageConfig.adminAddress, 'address')); + // @ts-ignore-next-line + tx.transferObjects([transferPolicyCap], tx.pure(mainPackageConfig.adminAddress)); return true; } + +const createTransferPolicy = ( + tx: TransactionBlock, + itemType: string, + publisher: ObjectArgument, +): TransactionArgument => { + let [transferPolicy, transferPolicyCap] = tx.moveCall({ + target: `0x2::transfer_policy::new`, + typeArguments: [itemType], + arguments: [tx.object(publisher)], + }); + + tx.moveCall({ + target: `0x2::transfer::public_share_object`, + typeArguments: [`0x2::transfer_policy::TransferPolicy<${itemType}>`], + arguments: [transferPolicy], + }); + + return transferPolicyCap; +} \ No newline at end of file From e6dec47257527809ebee20b592b1bfb7d983c980 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Wed, 27 Mar 2024 11:43:38 -0400 Subject: [PATCH 10/14] remove register with oracle --- .../register_with_oracle.ts | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 scripts/register_with_oracle/register_with_oracle.ts diff --git a/scripts/register_with_oracle/register_with_oracle.ts b/scripts/register_with_oracle/register_with_oracle.ts deleted file mode 100644 index 15211f64..00000000 --- a/scripts/register_with_oracle/register_with_oracle.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { mainPackage } from "../config/constants"; -import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js"; -import dotenv from "dotenv"; -import { executeTx, prepareSigner } from "../airdrop/helper"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { SuiClient } from "@mysten/sui.js/client"; -dotenv.config(); - -const setup = async () => { - const connection = new SuiPriceServiceConnection( - "https://hermes-beta.pyth.network" - ); - // You can find the ids of prices at https://pyth.network/developers/price-feed-ids - const priceIds = ["0x50c67b3fd225db8912a424dd4baed60ffdde625ed2feaaf283724f9608fea266"]; // SUI/USD - - // In order to use Pyth prices in your protocol you need to submit the price update data to Pyth contract in your target - // chain. `getPriceUpdateData` creates the update data which can be submitted to your contract. - const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIds); - - // https://docs.pyth.network/price-feeds/contract-addresses/sui - const wormholeStateId = "0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02"; - const pythStateId = "0x2d82612a354f0b7e52809fc2845642911c7190404620cec8688f68808f8800d8"; - - let suiClient = new SuiClient({ - url: "https://suins-rpc.testnet.sui.io:443" - }); - const client = new SuiPythClient(suiClient, pythStateId, wormholeStateId); - const txb = new TransactionBlock(); - let priceInfoObjectIds = await client.updatePriceFeeds(txb, priceUpdateData, priceIds); - - const setup = mainPackage["testnet"]; - const [sui_coin] = txb.splitCoins(txb.gas, [txb.pure(20)]); - const nft = txb.moveCall({ - target: `${setup.registrationPackageId}::register::register`, - arguments: [ - txb.object(setup.suins), // suins: &mut SuiNS - txb.object("test_domain"), // domain_name: String - txb.pure(1), // no_years: u8 - sui_coin, // payment: Coin - txb.object(priceInfoObjectIds[0]), // price_info_object: &PriceInfoObject - // clock: &Clock - // ctx: &mut TxContext - ], - }); - txb.transferObjects([nft], txb.pure.address('insert_address')) // send to tx sender - - return executeTx(prepareSigner(), txb, setup.client); -}; - -setup(); \ No newline at end of file From f47cebf91fdf1c72ca81942114d6080b0e39a1e8 Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Wed, 27 Mar 2024 12:41:48 -0400 Subject: [PATCH 11/14] tx build instead of serialize --- scripts/airdrop/helper.ts | 8 ++++---- scripts/package.json | 7 +++++-- scripts/pnpm-lock.yaml | 31 ++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/scripts/airdrop/helper.ts b/scripts/airdrop/helper.ts index 41dca6df..24a1b7c6 100644 --- a/scripts/airdrop/helper.ts +++ b/scripts/airdrop/helper.ts @@ -10,6 +10,8 @@ import { isValidSuiAddress, normalizeSuiAddress, toB64 } from "@mysten/sui.js/ut import { ExecutionStatus, GasCostSummary, SuiClient, SuiTransactionBlockResponse } from "@mysten/sui.js/client"; import { bcs } from "@mysten/sui.js/bcs"; import { SignerWithProvider } from "@mysten/sui.js/src/signers/signer-with-provider"; +import dotenv from "dotenv"; +dotenv.config(); export const MAX_MINTS_PER_TRANSACTION = 2_000; export const TOTAL_RANDOM_ADDRESSES = 48 * MAX_MINTS_PER_TRANSACTION; // attempt with 95K. @@ -119,7 +121,6 @@ export const batchToHash = (batch: string[]) => { .digest('hex') } - export const prepareSigner = (): Ed25519Keypair => { const phrase = process.env.ADMIN_PHRASE || ''; if (!phrase) throw new Error(`ERROR: Admin mnemonic is not exported! Please run 'export ADMIN_PHRASE=""'`); @@ -179,7 +180,7 @@ export const prepareMultisigTx = async ( if(gasObjectId) await setupGasPayment(tx, gasObjectId, config.client); // first do a dryRun, to make sure we are getting a success. - const dryRun = await inspectTransaction(tx, config.client, network); + const dryRun = await inspectTransaction(tx, config.client, network); if(!dryRun) throw new Error("This transaction failed."); @@ -217,10 +218,9 @@ const setupGasPayment = async (tx: TransactionBlock, gasObjectId: string, client export const inspectTransaction = async (tx: TransactionBlock, client: SuiClient, network: Network) => { const config = mainPackage[network]; - const result = await client.dryRunTransactionBlock( { - transactionBlock: tx.serialize() + transactionBlock: await tx.build({client: config.client}) } ); // log the result. diff --git a/scripts/package.json b/scripts/package.json index cfb1e891..56c926a4 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -9,7 +9,7 @@ "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", "publish-discounts": "ts-node transactions/publish_discounts.ts", @@ -25,10 +25,13 @@ "@mysten/bcs": "0.11.1", "@mysten/kiosk": "0.8.4", "@mysten/sui.js": "0.51.0", - "@types/blake2": "^4.0.1", "@pythnetwork/pyth-sui-js": "2.0.0", + "@types/blake2": "^4.0.1", "dotenv": "^16.3.1", "ts-node": "^10.9.1", "typescript": "^5.1.6" + }, + "devDependencies": { + "@types/node": "^20.11.30" } } diff --git a/scripts/pnpm-lock.yaml b/scripts/pnpm-lock.yaml index 2727ece2..d2ddacf2 100644 --- a/scripts/pnpm-lock.yaml +++ b/scripts/pnpm-lock.yaml @@ -19,17 +19,22 @@ dependencies: version: 2.0.0 '@types/blake2': specifier: ^4.0.1 - version: 4.0.1 + version: 4.0.4 dotenv: specifier: ^16.3.1 version: 16.3.1 ts-node: specifier: ^10.9.1 - version: 10.9.1(@types/node@20.3.3)(typescript@5.1.6) + version: 10.9.1(@types/node@20.11.30)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.1.6 +devDependencies: + '@types/node': + specifier: ^20.11.30 + version: 20.11.30 + packages: /@0no-co/graphql.web@1.0.4(graphql@16.8.1): @@ -233,20 +238,21 @@ packages: resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} dev: false - /@types/blake2@4.0.1: - resolution: {integrity: sha512-zcBydVD4uEsGo5gFRfm2phVMLqgrGJqcTZaT6lkZMWJzYovUi6wwraUJKdY1eO92q0bhWWVSAH4OnSp2m7rCfQ==} + /@types/blake2@4.0.4: + resolution: {integrity: sha512-r84TojGHMbBoH91XQjqoc1N89xy/LmcGb15k9OSdB2APb+xQfNcfbcFGMa9RbMmFsnIKCRDMpuKHBM04AwdgxQ==} dependencies: - '@types/node': 20.3.3 + '@types/node': 20.11.30 dev: false - /@types/node@20.3.3: - resolution: {integrity: sha512-wheIYdr4NYML61AjC8MKj/2jrR/kDQri/CIpVoZwldwhnIrD/j9jIU5bJ8yBKuB2VhpFV7Ab6G2XkBjv9r9Zzw==} - dev: false + /@types/node@20.11.30: + resolution: {integrity: sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==} + dependencies: + undici-types: 5.26.5 /@types/ws@8.5.10: resolution: {integrity: sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==} dependencies: - '@types/node': 20.3.3 + '@types/node': 20.11.30 dev: false /acorn-walk@8.2.0: @@ -421,7 +427,7 @@ packages: resolution: {integrity: sha512-PGcnJoTBnVGy6yYNFxWVNkdcAuAMstvutN9MgDJIV6L0oG8fB+ZNNy1T+wJzah8RPGor1mZuPQkVfXNDpy9eHA==} dev: false - /ts-node@10.9.1(@types/node@20.3.3)(typescript@5.1.6): + /ts-node@10.9.1(@types/node@20.11.30)(typescript@5.1.6): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -440,7 +446,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 20.3.3 + '@types/node': 20.11.30 acorn: 8.9.0 acorn-walk: 8.2.0 arg: 4.1.3 @@ -468,6 +474,9 @@ packages: hasBin: true dev: false + /undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} dev: false From a914e6a90c59bfa3b27210ddf251d18e9b41080b Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Wed, 27 Mar 2024 13:53:34 -0400 Subject: [PATCH 12/14] create policy using kiosk client --- scripts/day_one/setup.ts | 36 +++++++----------------- scripts/reserved-names/transfer-names.ts | 4 --- scripts/transactions/authorize_utils.ts | 7 ----- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/scripts/day_one/setup.ts b/scripts/day_one/setup.ts index 3a01c112..e78b5d56 100644 --- a/scripts/day_one/setup.ts +++ b/scripts/day_one/setup.ts @@ -1,7 +1,7 @@ import { TransactionArgument, TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, mainPackage } from "../config/constants"; import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one"; -import { Network as KioskNetwork, ObjectArgument } from "@mysten/kiosk"; +import { Network as KioskNetwork, ObjectArgument, TransferPolicyTransaction } from "@mysten/kiosk"; import { KioskClient } from '@mysten/kiosk'; export const dayOneType = (config: AirdropConfig) => `${config.packageId}::day_one::DayOne`; @@ -58,32 +58,16 @@ export const createDayOneTransferPolicy = async ( console.warn(`Type ${dayOneType} already had a tranfer policy so the transaction was skipped.`); return false; } + // create transfer policy - let transferPolicyCap = createTransferPolicy(tx, dayOneType(config), config.publisher) as TransactionArgument; - + let tpTx = new TransferPolicyTransaction({ kioskClient, transactionBlock: tx }); + await tpTx.create({ + type: `${dayOneType(config)}`, + publisher: config.publisher + }); + // transfer cap to owner - // @ts-ignore-next-line - tx.transferObjects([transferPolicyCap], tx.pure(mainPackageConfig.adminAddress)); + tpTx.shareAndTransferCap(mainPackageConfig.adminAddress); return true; - } - -const createTransferPolicy = ( - tx: TransactionBlock, - itemType: string, - publisher: ObjectArgument, -): TransactionArgument => { - let [transferPolicy, transferPolicyCap] = tx.moveCall({ - target: `0x2::transfer_policy::new`, - typeArguments: [itemType], - arguments: [tx.object(publisher)], - }); - - tx.moveCall({ - target: `0x2::transfer::public_share_object`, - typeArguments: [`0x2::transfer_policy::TransferPolicy<${itemType}>`], - arguments: [transferPolicy], - }); - - return transferPolicyCap; -} \ No newline at end of file + } \ No newline at end of file diff --git a/scripts/reserved-names/transfer-names.ts b/scripts/reserved-names/transfer-names.ts index 87d4cbc1..45d4bc86 100644 --- a/scripts/reserved-names/transfer-names.ts +++ b/scripts/reserved-names/transfer-names.ts @@ -82,10 +82,6 @@ const prepareTx = () => { txb.transferObjects([...objects.map(x => txb.object(x))], txb.pure(recipient)); } - txb.build({ - client: new SuiClient({url: ''}) - }); - return prepareMultisigTx(txb, 'mainnet'); } diff --git a/scripts/transactions/authorize_utils.ts b/scripts/transactions/authorize_utils.ts index b84fb87d..720bb604 100644 --- a/scripts/transactions/authorize_utils.ts +++ b/scripts/transactions/authorize_utils.ts @@ -6,7 +6,6 @@ dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../airdrop/helper"; import { TransactionBlock } from "@mysten/sui.js/transactions"; import { Network, mainPackage } from "../config/constants"; -import { SuiClient } from "@mysten/sui.js/client"; export const authorizeDirectSetupApp = async (network: Network) => { const tx = new TransactionBlock(); @@ -23,12 +22,6 @@ export const authorizeDirectSetupApp = async (network: Network) => { typeArguments: [`${config.directSetupPackageId}::direct_setup::DirectSetup`], }); - tx.build({ - client: new SuiClient({ - url: '' - }) - }) - // for mainnet, we just prepare multisig TX if(network === 'mainnet') return prepareMultisigTx(tx, 'mainnet'); From ed2adc488c8b280e5db1a1ef40e2ad577d824fae Mon Sep 17 00:00:00 2001 From: Aslan Tashtanov Date: Thu, 28 Mar 2024 07:38:30 -0400 Subject: [PATCH 13/14] update latest scripts --- scripts/transactions/renewals/authorize_renewals.ts | 5 +++-- scripts/transactions/reserved_names/extend_reserved_names.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/transactions/renewals/authorize_renewals.ts b/scripts/transactions/renewals/authorize_renewals.ts index b847d305..f26763b4 100644 --- a/scripts/transactions/renewals/authorize_renewals.ts +++ b/scripts/transactions/renewals/authorize_renewals.ts @@ -4,8 +4,9 @@ import dotenv from "dotenv"; dotenv.config(); import { executeTx, prepareMultisigTx, prepareSigner } from "../../airdrop/helper"; -import { MIST_PER_SUI, TransactionBlock } from "@mysten/sui.js"; +import { MIST_PER_SUI } from "@mysten/sui.js/utils"; import { Network, mainPackage } from "../../config/constants"; +import { TransactionBlock } from "@mysten/sui.js/transactions"; export const authorize = async (network: Network) => { const txb = new TransactionBlock(); @@ -43,7 +44,7 @@ export const authorize = async (network: Network) => { // for mainnet, we just prepare multisig TX if(network === 'mainnet') return prepareMultisigTx(txb, 'mainnet'); - return executeTx(prepareSigner(config.provider), txb); + return executeTx(prepareSigner(), txb, config.client); } authorize("mainnet"); diff --git a/scripts/transactions/reserved_names/extend_reserved_names.ts b/scripts/transactions/reserved_names/extend_reserved_names.ts index 8d177240..0785daf6 100644 --- a/scripts/transactions/reserved_names/extend_reserved_names.ts +++ b/scripts/transactions/reserved_names/extend_reserved_names.ts @@ -1,7 +1,9 @@ -import { MIST_PER_SUI, SUI_CLOCK_OBJECT_ID, SuiObjectRef, TransactionArgument, TransactionBlock } from "@mysten/sui.js"; import { PackageInfo, mainPackage } from "../../config/constants" import reservedObjects from "../../reserved-names/owned-objects.json"; import { prepareMultisigTx } from "../../airdrop/helper"; +import { MIST_PER_SUI, SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils"; +import { TransactionArgument, TransactionBlock } from "@mysten/sui.js/transactions"; +import { SuiObjectRef } from "@mysten/sui.js/client"; const RUN = process.env.RUN_ID || ''; From 73b532ced785464f1ec41ed5737042f2349c52a2 Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Thu, 28 Mar 2024 14:09:10 +0200 Subject: [PATCH 14/14] Replace blake2b with another dep --- scripts/airdrop/helper.ts | 11 +++----- scripts/package.json | 6 ++--- scripts/pnpm-lock.yaml | 53 +++++++++++++++++---------------------- 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/scripts/airdrop/helper.ts b/scripts/airdrop/helper.ts index 811f76d7..f0952d0f 100644 --- a/scripts/airdrop/helper.ts +++ b/scripts/airdrop/helper.ts @@ -1,15 +1,12 @@ import { TransactionArgument, TransactionBlock } from "@mysten/sui.js/transactions"; import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519'; -import * as blake2 from 'blake2'; +import { blake2b } from '@noble/hashes/blake2b'; import fs from "fs"; import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one"; import { Network, mainPackage } from "../config/constants"; -import { execSync } from 'child_process'; -import { RawSigner } from "@mysten/sui.js/src/signers/raw-signer"; import { isValidSuiAddress, normalizeSuiAddress, toB64 } from "@mysten/sui.js/utils"; import { ExecutionStatus, GasCostSummary, SuiClient, SuiTransactionBlockResponse } from "@mysten/sui.js/client"; import { bcs } from "@mysten/sui.js/bcs"; -import { SignerWithProvider } from "@mysten/sui.js/src/signers/signer-with-provider"; import dotenv from "dotenv"; dotenv.config(); @@ -114,11 +111,9 @@ export const serializeBatchToBytes = (batch: string[]) => { export const batchToHash = (batch: string[]) => { const bytes = Buffer.from(serializeBatchToBytes(batch)); + const digest = blake2b(bytes, { dkLen: 32}); - return blake2 - .createHash('blake2b', { digestLength: 32 }) - .update(bytes) - .digest('hex') + return Buffer.from(digest).toString('hex'); } export const prepareSigner = (): Ed25519Keypair => { diff --git a/scripts/package.json b/scripts/package.json index 5e62884f..5b0eebfe 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -7,7 +7,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "transactions::main_package::upgrade": "ts-node transactions/main_package_upgrade.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", "authorize-utils": "ts-node transactions/authorize_utils.ts", "authorize-discounts": "ts-node transactions/quest_3_setup.ts", "disable-free-claims": "ts-node transactions/quest3/disable_free_claims.ts", @@ -23,13 +23,13 @@ "@mysten/bcs": "0.11.1", "@mysten/kiosk": "0.8.4", "@mysten/sui.js": "0.51.0", + "@noble/hashes": "^1.4.0", "@pythnetwork/pyth-sui-js": "2.0.0", - "@types/blake2": "^4.0.1", "dotenv": "^16.3.1", - "ts-node": "^10.9.1", "typescript": "^5.1.6" }, "devDependencies": { + "ts-node": "^10.9.1", "@types/node": "^20.11.30" } } diff --git a/scripts/pnpm-lock.yaml b/scripts/pnpm-lock.yaml index d2ddacf2..f2442ffd 100644 --- a/scripts/pnpm-lock.yaml +++ b/scripts/pnpm-lock.yaml @@ -14,18 +14,15 @@ dependencies: '@mysten/sui.js': specifier: 0.51.0 version: 0.51.0 + '@noble/hashes': + specifier: ^1.4.0 + version: 1.4.0 '@pythnetwork/pyth-sui-js': specifier: 2.0.0 version: 2.0.0 - '@types/blake2': - specifier: ^4.0.1 - version: 4.0.4 dotenv: specifier: ^16.3.1 version: 16.3.1 - ts-node: - specifier: ^10.9.1 - version: 10.9.1(@types/node@20.11.30)(typescript@5.1.6) typescript: specifier: ^5.1.6 version: 5.1.6 @@ -34,6 +31,9 @@ devDependencies: '@types/node': specifier: ^20.11.30 version: 20.11.30 + ts-node: + specifier: ^10.9.1 + version: 10.9.1(@types/node@20.11.30)(typescript@5.1.6) packages: @@ -60,7 +60,7 @@ packages: engines: {node: '>=12'} dependencies: '@jridgewell/trace-mapping': 0.3.9 - dev: false + dev: true /@gql.tada/cli-utils@0.3.0: resolution: {integrity: sha512-kDebLVuM5r3/bI1MmlhHr9VKHxXeq8Gxy1wHVTPva4R5ObfbhzxnHsTCvR6MUp8ziy9Pg9MESb8S1YZW8ohM3A==} @@ -87,18 +87,18 @@ packages: /@jridgewell/resolve-uri@3.1.1: resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==} engines: {node: '>=6.0.0'} - dev: false + dev: true /@jridgewell/sourcemap-codec@1.4.15: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} - dev: false + dev: true /@jridgewell/trace-mapping@0.3.9: resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} dependencies: '@jridgewell/resolve-uri': 3.1.1 '@jridgewell/sourcemap-codec': 1.4.15 - dev: false + dev: true /@mysten/bcs@0.10.1: resolution: {integrity: sha512-cQDb7Rhz2J82ZqgVQiHykuwKUlgiLWS2bjoajPPW0uvXlb75qrgKuaxh1UzsaRhHy3egk/APc0xjiZoqdbzB4w==} @@ -224,25 +224,19 @@ packages: /@tsconfig/node10@1.0.9: resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} - dev: false + dev: true /@tsconfig/node12@1.0.11: resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} - dev: false + dev: true /@tsconfig/node14@1.0.3: resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} - dev: false + dev: true /@tsconfig/node16@1.0.4: resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} - dev: false - - /@types/blake2@4.0.4: - resolution: {integrity: sha512-r84TojGHMbBoH91XQjqoc1N89xy/LmcGb15k9OSdB2APb+xQfNcfbcFGMa9RbMmFsnIKCRDMpuKHBM04AwdgxQ==} - dependencies: - '@types/node': 20.11.30 - dev: false + dev: true /@types/node@20.11.30: resolution: {integrity: sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==} @@ -258,17 +252,17 @@ packages: /acorn-walk@8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} - dev: false + dev: true /acorn@8.9.0: resolution: {integrity: sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==} engines: {node: '>=0.4.0'} hasBin: true - dev: false + dev: true /arg@4.1.3: resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} - dev: false + dev: true /asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} @@ -325,7 +319,7 @@ packages: /create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - dev: false + dev: true /delayed-stream@1.0.0: resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} @@ -335,7 +329,7 @@ packages: /diff@4.0.2: resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} engines: {node: '>=0.3.1'} - dev: false + dev: true /dotenv@16.3.1: resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} @@ -396,7 +390,7 @@ packages: /make-error@1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - dev: false + dev: true /mime-db@1.52.0: resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} @@ -456,7 +450,7 @@ packages: typescript: 5.1.6 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - dev: false + dev: true /tweetnacl@1.0.3: resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==} @@ -466,7 +460,6 @@ packages: resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==} engines: {node: '>=14.17'} hasBin: true - dev: false /typescript@5.4.3: resolution: {integrity: sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==} @@ -479,7 +472,7 @@ packages: /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - dev: false + dev: true /ws@8.16.0: resolution: {integrity: sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==} @@ -497,4 +490,4 @@ packages: /yn@3.1.1: resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} engines: {node: '>=6'} - dev: false + dev: true