Module Initialization

Below we will describe and implement the flow for our init_module function.

Create Named Object: Call create_named_object to store the FA resources in. This object is commonly referred to as the Metadata object. Instead of creating a random address, we make the address dependent on the seed. This allows us to retrieve the object’s address easily.

Create Primary Store Enabled Fungible Asset:

  • Calls create_primary_store_enabled_fungible_asset.
  • Creates a fungible asset with primary store support.
  • This function calls add_fungibility.

Store Resources:

  • Stores Metadata and Supply resources in the Metadata object.
  • Store Roles, Management, and State resources in the Metadata object.

/// Called as part of deployment to initialize the stablecoin.
fun init_module(usdk_signer: &signer) {
let constructor_ref = &object::create_named_object(usdk_signer, ASSET_SYMBOL);
primary_fungible_store::create_primary_store_enabled_fungible_asset(
constructor_ref,
option::none(),
utf8(ASSET_SYMBOL), /* name */
utf8(ASSET_SYMBOL), /* symbol */
8, /* decimals */
utf8(b"http://example.com/favicon.ico"), /* icon */
utf8(b"http://example.com"), /* project */
);
// All resources created will be kept in the asset metadata object.
let metadata_object_signer = &object::generate_signer(constructor_ref);
move_to(metadata_object_signer, Roles {
master_minter: @master_minter,
minters: vector[@minter],
denylister: @denylister,
});
// Create mint/burn/transfer refs to allow creator to manage the stablecoin.
move_to(metadata_object_signer, Management {
extend_ref: object::generate_extend_ref(constructor_ref),
mint_ref: fungible_asset::generate_mint_ref(constructor_ref),
burn_ref: fungible_asset::generate_burn_ref(constructor_ref),
transfer_ref: fungible_asset::generate_transfer_ref(constructor_ref),
});
move_to(metadata_object_signer, State {
denylist: smart_table::new(),
});
}