Wrapper Module
Overview
The satay::wrapper
module manages the conversion of the legacy coin standard to-and-fro the fungible assets standard within the Satay protocol. It handles the creation, initialization, and management of wrapped coins by providing functions to wrap and unwrap them.
Structs
Wrapper
The Wrapper
struct stores a SignerCapability
for managing wrapped coins and a SmartTable
that maps wrapped coin metadata to their coin type names.
Constants
WRAPPER_SEED:
vector<u8> = b"000000000Wrapper"
– The seed used to create the wrapper resource account.EWRAPPER_ALREADY_INITIALIZED:
u64 = 0
– Error indicating that the wrapper has already been initialized.EWRAPPER_NOT_INITIALIZED:
u64 = 1
– Error indicating that the wrapper has not been initialized.EMETADATA_ALREADY_EXISTS:
u64 = 2
– Error indicating that the metadata for the wrapped asset already exists.
Public Functions
Module Initialization
init_module(_: &signer)
: Initializes the wrapper module by creating a new wrapper account. It generates a new signer and aWrapper
resource, storing wrapped coins in aSmartTable
.
Asset Initialization and Management
initialize_wrapped_asset<CoinType>(): Object<Metadata> acquires Wrapper
: Initializes a new wrapped asset for the givenCoinType
. It creates metadata for the wrapped asset and stores it in the wrapper'sSmartTable
. If the metadata already exists, it raisesEMETADATA_ALREADY_EXISTS
.get_wrapped_asset_metadata<CoinType>(): Object<Metadata>
: Retrieves the metadata for a wrapped asset of the givenCoinType
.get_wrapped_coin_type(metadata: Object<Metadata>): String acquires Wrapper
: Retrieves the coin type name of the given wrapped asset from the wrapper'sSmartTable
.is_wrapped_asset(metadata: Object<Metadata>): bool acquires Wrapper
: Checks whether the given metadata represents a wrapped asset.
Address Management
get_wrapper_address(): address
: Computes and returns the address of the wrapper resource.compute_wrap_address<CoinType>(): address
: Computes the address of the wrapped asset for the givenCoinType
.
Asset Wrapping and Unwrapping
wrap<CoinType>(coin: Coin<CoinType>): FungibleAsset acquires Wrapper
: Wraps the givenCoinType
into a fungible asset. It initializes the wrapped asset if it doesn't exist, deposits the coin into the wrapper, and mints the corresponding fungible asset.unwrap<CoinType>(asset: FungibleAsset): Coin<CoinType> acquires Wrapper
: Unwraps a fungible asset into the correspondingCoinType
. It burns the fungible asset and withdraws the equivalent amount of the original coin.
Helper Functions
borrow_wrapper()
: Returns a reference to theWrapper
resource.borrow_wrapper_mut()
: Returns a mutable reference to theWrapper
resource.
View Functions
has_wrapped_asset<CoinType>(): bool
: Checks if the wrapped asset for the givenCoinType
exists.get_wrapped_asset_metadata<CoinType>(): Object<Metadata>
: Retrieves the metadata for the wrapped asset corresponding toCoinType
.
Last updated