Skip to content

Commit

Permalink
day_one migration (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
leecchh authored Apr 20, 2024
1 parent 6e79d9d commit b64bc1c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 100 deletions.
2 changes: 1 addition & 1 deletion packages/day_one/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ published-at="0xbf1431324a4a6eadd70e0ac6c5a16f36492f255ed4d011978b2cf34ad738efe6
edition = "2024.beta"

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

suins = { local = "../suins" }

Expand Down
37 changes: 19 additions & 18 deletions packages/day_one/sources/bogo.move
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// A simple BOGO that allows a `DayOne` holder to trade
/// A simple BOGO that allows a `DayOne` holder to trade
/// a domain registered before the expiration day we set
/// with another one of the same size.
///
///
module day_one::bogo {
use std::string::{Self, String};

use sui::clock::{Clock};
use sui::dynamic_field::{Self as df};

use suins::config;
use suins::domain::{Self, Domain};
use suins::suins::{Self, SuiNS};
use suins::suins_registration::{Self as nft, SuinsRegistration};
use suins::registry::Registry;

use sui::{
clock::{Clock},
dynamic_field::{Self as df},
};
use suins::{
config,
domain::{Self, Domain},
suins::{Self, SuiNS},
suins_registration::SuinsRegistration,
registry::Registry,
};
use day_one::day_one::{Self, DayOne};

/// Authorization token for the BOGO app.
Expand All @@ -28,7 +29,7 @@ module day_one::bogo {
public struct UsedInDayOnePromo has copy, store, drop { }

// This will define if a domain name was bought in an auction.
// The only way to understand that, is to check that the expiration day is
// The only way to understand that, is to check that the expiration day is
// less than last_day of auctions + 1 year.
const LAST_VALID_EXPIRATION_DATE: u64 = 1721499031 * 1000; // Saturday, 20 July 2024 18:10:31 UTC

Expand Down Expand Up @@ -60,7 +61,7 @@ module day_one::bogo {
assert!(!used_in_promo(domain_nft), EDomainAlreadyUsed);

// Verify that the domain was bought in an auction.
// We understand if a domain was bought in an auction if the expiry date is less than the last day of auction + 1 year.
// We understand if a domain was bought in an auction if the expiry date is less than the last day of auction + 1 year.
assert!(domain_nft.expiration_timestamp_ms() <= LAST_VALID_EXPIRATION_DATE, ENotPurchasedInAuction);

// generate a domain out of the input string.
Expand All @@ -82,7 +83,7 @@ module day_one::bogo {
let registry = suins::app_registry_mut<BogoApp, Registry>(BogoApp {}, suins);
let mut nft = registry.add_record(new_domain, DEFAULT_DURATION, clock, ctx);

// mark both the new and the current domain presented as used, so that they can't
// mark both the new and the current domain presented as used, so that they can't
// be redeemed twice in this deal.
mark_domain_as_used(domain_nft);
mark_domain_as_used(&mut nft);
Expand All @@ -92,12 +93,12 @@ module day_one::bogo {

// Returns the size of a domain name. (e.g test.sui -> 4)
fun domain_length(domain: &Domain): u64{
string::length(domain::sld(domain))
string::length(domain.sld())
}

// Check if the domain has been minted for free from this bogo promo.
public fun used_in_promo(domain_nft: &SuinsRegistration): bool {
df::exists_(nft::uid(domain_nft), UsedInDayOnePromo {})
df::exists_(domain_nft.uid(), UsedInDayOnePromo {})
}

public fun last_valid_expiration(): u64 {
Expand All @@ -106,7 +107,7 @@ module day_one::bogo {

/// Attaches a DF that marks a domain as `used` in another day 1 object.
fun mark_domain_as_used(domain_nft: &mut SuinsRegistration) {
df::add(nft::uid_mut(domain_nft), UsedInDayOnePromo {}, true)
df::add(domain_nft.uid_mut(), UsedInDayOnePromo {}, true)
}

}
38 changes: 20 additions & 18 deletions packages/day_one/sources/day_one.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

/// This module defines the `DayOne` Object airdropped to early supporters of the SuiNS project.
module day_one::day_one {

use sui::package;
use sui::tx_context::{sender};
use sui::hash;
use sui::dynamic_field as df;
use sui::bcs;

use sui::{
package,
tx_context::{sender},
hash,
dynamic_field as df,
bcs,
};

// We mark as friend just the BOGO module.
// This is the only one that can activate a DayOne object.
// This is a one-time operation that won't happen from any other modules.
/* friend day_one::bogo; */

/// The shared object that stores the receivers destination.
public struct DropList has key {
public struct DropList has key {
id: UID,
total_minted: u32
}
Expand All @@ -25,7 +27,7 @@ module day_one::day_one {
/// publish. Consumed in the setup call.
public struct SetupCap has key { id: UID }

/// == ERRORS ==
/// == ERRORS ==
// Error emitted when trying to mint with invalid addresses (non existent DF).
const ENotFound: u64 = 0;

Expand All @@ -39,7 +41,7 @@ module day_one::day_one {
fun init(otw: DAY_ONE, ctx: &mut TxContext) {
// Claim the `Publisher` for the package!
package::claim_and_keep(otw, ctx);

transfer::share_object(DropList { id: object::new(ctx), total_minted: 0 });
// For SuiNS, we need 1 SetupCap to manage all the required addresses. We'll be setting up around 75K addresses.
// We can mint 2K objects per run!
Expand All @@ -48,7 +50,7 @@ module day_one::day_one {

/// The DayOne object, granting participants special offers in
/// different future promotions.
public struct DayOne has key, store {
public struct DayOne has key, store {
id: UID,
active: bool,
serial: u32
Expand All @@ -68,12 +70,12 @@ module day_one::day_one {

// fails if not found.
let lookup = df::remove_if_exists(&mut self.id, sui::address::from_bytes(hash));
assert!(option::is_some<bool>(&lookup), ENotFound);
assert!(lookup.is_some<bool>(), ENotFound);

let mut i: u32 = self.total_minted;

while (vector::length(&recipients) > 0) {
let recipient = vector::pop_back(&mut recipients);
let recipient = recipients.pop_back();
transfer::public_transfer(DayOne {
id: object::new(ctx),
active: false,
Expand All @@ -94,21 +96,21 @@ module day_one::day_one {
cap: SetupCap,
mut hashes: vector<address>,
) {
// verify we only pass less than 1000 hashes at the setup.
// verify we only pass less than 1000 hashes at the setup.
// That's the max amount of DFs we can create in a single run.
assert!(vector::length(&hashes) <= 1000, ETooManyHashes);
assert!(hashes.length() <= 1000, ETooManyHashes);

let SetupCap { id } = cap;
id.delete();

// attach every hash as a dynamic field to the `DropList` object;
while (vector::length(&hashes) > 0) {
df::add(&mut self.id, vector::pop_back(&mut hashes), true);
while (hashes.length() > 0) {
df::add(&mut self.id, hashes.pop_back(), true);
};
}

// Private helper to activate the DayOne object
// Will only be called by the `bogo` module (friend), which marks the
// Will only be called by the `bogo` module (friend), which marks the
// beggining of the DayOne promotions.
public(package) fun activate(self: &mut DayOne) {
self.active = true
Expand Down
Loading

0 comments on commit b64bc1c

Please sign in to comment.