Skip to content
37 changes: 19 additions & 18 deletions contracts/sources/cooler_factory.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ module galliun::cooler_factory {
sui::SUI,
coin::{Coin}
};
use galliun::water_cooler::{Self};
use galliun::orchestrator::{Self};
use galliun::{
water_cooler::{Self},
orchestrator::{Self},
settings::{Self},
warehouse::{Self},
};

// === Errors ===

Expand All @@ -19,7 +23,6 @@ module galliun::cooler_factory {
public struct CoolerFactory has key {
id: UID,
fee: u64,
mint_fee: u64,
treasury: address,
cooler_list: vector<ID>
}
Expand All @@ -38,7 +41,6 @@ module galliun::cooler_factory {
CoolerFactory {
id: object::new(ctx),
fee: 100_000_000,
mint_fee: 100_000,
treasury: @galliun_treasury,
cooler_list: vector::empty()
}
Expand All @@ -58,6 +60,14 @@ module galliun::cooler_factory {
) {
assert!(payment.value() == self.fee, EInsufficientBalance);

// Create a Mint distributer and give it to the buyer.
// We do this here to avoid create a dependency circle
// with the Mint and water_cooler modules
// let settings = settings::new(waterCoolerID, ctx);
// let warehouse = warehouse::new(waterCoolerID, ctx);

let (settings, warehouse) = orchestrator::create_mint_distributer(ctx);

// Create a WaterCooler and give it to the buyer
let waterCoolerID = water_cooler::create_water_cooler(
name,
Expand All @@ -66,18 +76,13 @@ module galliun::cooler_factory {
placeholder_image_url,
supply,
treasury,
// mint_setting_id,
// mint_warehouse_id,
object::id(&settings),
object::id(&warehouse),
ctx
);

// Create a Mint distributer and give it to the buyer.
// We do this here to avoid create a dependency circle
// with the Mint and water_cooler modules
let (settings, warehouse) = orchestrator::create_mint_distributer(waterCoolerID, ctx);
);

orchestrator::transfer_setting(settings);
orchestrator::transfer_warehouse(warehouse);
settings::transfer_setting(settings, ctx);
warehouse::transfer_warehouse(warehouse, ctx);

self.cooler_list.push_back(waterCoolerID);

Expand All @@ -93,10 +98,6 @@ module galliun::cooler_factory {
public fun get_fee(self: &CoolerFactory) : u64 {
self.fee
}

public fun get_mint_fee(self: &CoolerFactory) : u64 {
self.mint_fee
}

public(package) fun send_fees(
self: &CoolerFactory,
Expand Down
92 changes: 92 additions & 0 deletions contracts/sources/cooler_registry.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module galliun::cooler_registry {
// === Imports ===

use std::string::{String};
use sui::{
sui::SUI,
coin::{Coin},
table::{Self, Table}
};
use galliun::water_cooler::{WaterCooler};

// === Errors ===

const EInsufficientBalance: u64 = 0;
const NotTheOwner: u64 = 1;
const NameAlreadyRegistered: u64 = 2;

// === Structs ===

// shared object where creators register their Water cooler
// For it to be displayed on the launchpad
public struct CoolerRegistry has key {
id: UID,
fee: u64,
name_to_id: Table<String, ID>,
treasury: address,
}

public struct CoolerRegistryOwnerCap has key, store { id: UID }

// === Public mutative functions ===

fun init(ctx: &mut TxContext) {
transfer::transfer(
CoolerRegistryOwnerCap { id: object::new(ctx) },
ctx.sender()
);

transfer::share_object(
CoolerRegistry {
id: object::new(ctx),
fee: 100_000_000,
name_to_id: table::new(ctx),
treasury: @galliun_treasury,
}
);
}

public entry fun register_water_cooler(
self: &mut CoolerRegistry,
payment: Coin<SUI>,
waterCooler: &WaterCooler,
name: String,
ctx: &mut TxContext
) {
assert!(payment.value() == self.fee, EInsufficientBalance);
assert!(waterCooler.owner() == ctx.sender(), NotTheOwner);
assert!(!self.name_to_id.contains(name), NameAlreadyRegistered);

self.name_to_id.add(name, object::id(waterCooler));

// Transfer fees to treasury
self.send_fees(payment);
}


public entry fun update_fee(_: &CoolerRegistryOwnerCap, self: &mut CoolerRegistry, fee: u64) {
self.fee = fee;
}

public fun get_fee(self: &CoolerRegistry) : u64 {
self.fee
}

public fun get_water_cooler(self: &CoolerRegistry, name: String) : ID {
self.name_to_id[name]
}

public(package) fun send_fees(
self: &CoolerRegistry,
coins: Coin<SUI>
) {
transfer::public_transfer(coins, self.treasury);
}

// === Test Functions ===

#[test_only]
public fun init_for_cooler(ctx: &mut TxContext) {
init(ctx);
}
}
2 changes: 1 addition & 1 deletion contracts/sources/factory_settings.move
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module galliun::factory_settings {
// === Test Functions ===

#[test_only]
public fun init_for_cooler(ctx: &mut TxContext) {
public fun init_for_factory_settings(ctx: &mut TxContext) {
init(ctx);
}
}
19 changes: 8 additions & 11 deletions contracts/sources/image.move
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module galliun::image {
use std::string::{String};

// === Imports ===

Expand All @@ -10,24 +11,20 @@ module galliun::image {

public struct Image has key, store {
id: UID,
name: vector<u8>,
description: vector<u8>,
data: vector<u8>, // Binary data of the image
name: String,
description: String,
data: String, // Binary data of the image
}


// === Events ===



// === Init Function ===

/// Function to inscribe a new image on-chain
#[allow(lint(self_transfer))]
public fun inscribe_image(
name: vector<u8>,
description: vector<u8>,
data: vector<u8>,
name: String,
description: String,
data: String,
ctx: &mut TxContext
) {
let image = Image {
Expand All @@ -40,7 +37,7 @@ module galliun::image {
}

/// Function to get image metadata
public fun get_image_metadata(image: &Image): (vector<u8>, vector<u8>, vector<u8>) {
public fun get_image_metadata(image: &Image): (String, String, String) {
(image.name, image.description, image.data)
}
}
Loading