You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[resource_group_member(group = aptos_framework::object::ObjectGroup)]
struct ManagedFungibleAsset has key
{
mint_ref: MintRef,
transfer_ref: TransferRef,
burn_ref: BurnRef,
}
fun init_module(admin: &signer)
{
let constructor_ref = &object::create_named_object(admin, ASSET_SYMBOL);
primary_fungible_store::create_primary_store_enabled_fungible_asset(
constructor_ref,
option::none(),
utf8(b"HOLDER"),
utf8(ASSET_SYMBOL),
0,
utf8(b"https://akrd.net/HOLDER"),
utf8(b"https://linktr.ee/HOLDER")
);
let mint_ref = fungible_asset::generate_mint_ref(constructor_ref);
let burn_ref = fungible_asset::generate_burn_ref(constructor_ref);
let transfer_ref = fungible_asset::generate_transfer_ref(constructor_ref);
let metadata_object_signer = object::generate_signer(constructor_ref);
move_to(
&metadata_object_signer,
ManagedFungibleAsset { mint_ref, transfer_ref, burn_ref }
)
}
fun primary_store_address<T: key>(owner: address, metadata: Object<T>): address
{
let metadata_addr = object::object_address(&metadata);
object::create_user_derived_object_address(owner, metadata_addr)
}
fun primary_store<T: key>(owner: address, metadata: Object<T>): Object<FungibleStore>
{
let store = primary_store_address(owner, metadata);
object::address_to_object<FungibleStore>(store)
}
fun get_metadata(): Object<Metadata>
{
let asset_address = object::create_object_address(&@publisher, ASSET_SYMBOL);
object::address_to_object<Metadata>(asset_address)
}
entry fun get_tokens(to: address, amount: u64) acquires ManagedFungibleAsset
{
let asset = get_metadata();
let managed_fungible_asset = borrow_global<ManagedFungibleAsset>(object::object_address(&asset));
let to_wallet = primary_fungible_store::ensure_primary_store_exists(to, asset);
let fa = fungible_asset::mint(&managed_fungible_asset.mint_ref, amount);
fungible_asset::deposit_with_ref(&managed_fungible_asset.transfer_ref, to_wallet, fa);
}
public(friend) entry fun burn(from: address, amount: u8) acquires ManagedFungibleAsset
{
let asset = get_metadata();
let burn_ref = &borrow_global<ManagedFungibleAsset>(object::object_address(&asset)).burn_ref;
let from_wallet = primary_fungible_store::primary_store(from, asset);
fungible_asset::burn_from(burn_ref, from_wallet, amount as u64);
}
What am I trying to do? -
Create Soul Bound Tokens (coins?), which can only be minted to the user's wallet by the publisher (contract authority).
the tokens in the user's wallet should be burnable by the publisher
Assumptions -
Since I have the mint_ref, transfer_ref and burn_ref stored in the contract, I am guessing only the contract can do any type of minting, transfers and burning. And the users won't be able to transfer it from their wallet? Does that make it a SBT in Aptos?
Help -
If this code is wrong or there are better ways of doing this, please lmk how to achieve what I'm trying to do.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Discord user ID
memxor
Describe your question in detail.
This is my code -
What am I trying to do? -
Assumptions -
mint_ref
,transfer_ref
andburn_ref
stored in the contract, I am guessing only the contract can do any type of minting, transfers and burning. And the users won't be able to transfer it from their wallet? Does that make it a SBT in Aptos?Help -
Beta Was this translation helpful? Give feedback.
All reactions