-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,090 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# Contract `ExampleToken` | ||
|
||
```cadence | ||
contract ExampleToken { | ||
totalSupply: UFix64 | ||
VaultStoragePath: StoragePath | ||
ReceiverPublicPath: PublicPath | ||
VaultPublicPath: PublicPath | ||
AdminStoragePath: StoragePath | ||
} | ||
``` | ||
|
||
|
||
Implemented Interfaces: | ||
- `FungibleToken` | ||
|
||
## Structs & Resources | ||
|
||
### resource `Vault` | ||
|
||
```cadence | ||
resource Vault { | ||
balance: UFix64 | ||
} | ||
``` | ||
Each user stores an instance of only the Vault in their storage | ||
The functions in the Vault and governed by the pre and post conditions | ||
in FungibleToken when they are called. | ||
The checks happen at runtime whenever a function is called. | ||
|
||
Resources can only be created in the context of the contract that they | ||
are defined in, so there is no way for a malicious user to create Vaults | ||
out of thin air. A special Minter resource needs to be defined to mint | ||
new tokens. | ||
|
||
[More...](ExampleToken_Vault.md) | ||
|
||
--- | ||
|
||
### resource `Administrator` | ||
|
||
```cadence | ||
resource Administrator { | ||
} | ||
``` | ||
|
||
[More...](ExampleToken_Administrator.md) | ||
|
||
--- | ||
|
||
### resource `Minter` | ||
|
||
```cadence | ||
resource Minter { | ||
allowedAmount: UFix64 | ||
} | ||
``` | ||
Resource object that token admin accounts can hold to mint new tokens. | ||
|
||
[More...](ExampleToken_Minter.md) | ||
|
||
--- | ||
|
||
### resource `Burner` | ||
|
||
```cadence | ||
resource Burner { | ||
} | ||
``` | ||
Resource object that token admin accounts can hold to burn tokens. | ||
|
||
[More...](ExampleToken_Burner.md) | ||
|
||
--- | ||
## Functions | ||
|
||
### fun `createEmptyVault()` | ||
|
||
```cadence | ||
func createEmptyVault(): Vault | ||
``` | ||
Function that creates a new Vault with a balance of zero | ||
and returns it to the calling context. A user must call this function | ||
and store the returned Vault in their storage in order to allow their | ||
account to be able to receive deposits of this token type. | ||
|
||
Returns: The new Vault resource | ||
|
||
--- | ||
## Events | ||
|
||
### event `TokensInitialized` | ||
|
||
```cadence | ||
event TokensInitialized(initialSupply UFix64) | ||
``` | ||
The event that is emitted when the contract is created | ||
|
||
--- | ||
|
||
### event `TokensWithdrawn` | ||
|
||
```cadence | ||
event TokensWithdrawn(amount UFix64, from Address?) | ||
``` | ||
The event that is emitted when tokens are withdrawn from a Vault | ||
|
||
--- | ||
|
||
### event `TokensDeposited` | ||
|
||
```cadence | ||
event TokensDeposited(amount UFix64, to Address?) | ||
``` | ||
The event that is emitted when tokens are deposited to a Vault | ||
|
||
--- | ||
|
||
### event `TokensMinted` | ||
|
||
```cadence | ||
event TokensMinted(amount UFix64) | ||
``` | ||
The event that is emitted when new tokens are minted | ||
|
||
--- | ||
|
||
### event `TokensBurned` | ||
|
||
```cadence | ||
event TokensBurned(amount UFix64) | ||
``` | ||
The event that is emitted when tokens are destroyed | ||
|
||
--- | ||
|
||
### event `MinterCreated` | ||
|
||
```cadence | ||
event MinterCreated(allowedAmount UFix64) | ||
``` | ||
The event that is emitted when a new minter resource is created | ||
|
||
--- | ||
|
||
### event `BurnerCreated` | ||
|
||
```cadence | ||
event BurnerCreated() | ||
``` | ||
The event that is emitted when a new burner resource is created | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Resource `Administrator` | ||
|
||
```cadence | ||
resource Administrator { | ||
} | ||
``` | ||
|
||
## Functions | ||
|
||
### fun `createNewMinter()` | ||
|
||
```cadence | ||
func createNewMinter(allowedAmount UFix64): Minter | ||
``` | ||
Function that creates and returns a new minter resource | ||
|
||
Parameters: | ||
- allowedAmount : _The maximum quantity of tokens that the minter could create_ | ||
|
||
Returns: The Minter resource that would allow to mint tokens | ||
|
||
--- | ||
|
||
### fun `createNewBurner()` | ||
|
||
```cadence | ||
func createNewBurner(): Burner | ||
``` | ||
Function that creates and returns a new burner resource | ||
|
||
Returns: The Burner resource | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Resource `Burner` | ||
|
||
```cadence | ||
resource Burner { | ||
} | ||
``` | ||
|
||
Resource object that token admin accounts can hold to burn tokens. | ||
## Functions | ||
|
||
### fun `burnTokens()` | ||
|
||
```cadence | ||
func burnTokens(from FungibleToken.Vault) | ||
``` | ||
Function that destroys a Vault instance, effectively burning the tokens. | ||
|
||
Note: the burned tokens are automatically subtracted from the | ||
total supply in the Vault destructor. | ||
|
||
Parameters: | ||
- from : _The Vault resource containing the tokens to burn_ | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Resource `Minter` | ||
|
||
```cadence | ||
resource Minter { | ||
allowedAmount: UFix64 | ||
} | ||
``` | ||
|
||
Resource object that token admin accounts can hold to mint new tokens. | ||
|
||
### Initializer | ||
|
||
```cadence | ||
func init(allowedAmount UFix64) | ||
``` | ||
|
||
|
||
## Functions | ||
|
||
### fun `mintTokens()` | ||
|
||
```cadence | ||
func mintTokens(amount UFix64): ExampleToken.Vault | ||
``` | ||
Function that mints new tokens, adds them to the total supply, | ||
and returns them to the calling context. | ||
|
||
Parameters: | ||
- amount : _The quantity of tokens to mint_ | ||
|
||
Returns: The Vault resource containing the minted tokens | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Resource `Vault` | ||
|
||
```cadence | ||
resource Vault { | ||
balance: UFix64 | ||
} | ||
``` | ||
|
||
Each user stores an instance of only the Vault in their storage | ||
The functions in the Vault and governed by the pre and post conditions | ||
in FungibleToken when they are called. | ||
The checks happen at runtime whenever a function is called. | ||
|
||
Resources can only be created in the context of the contract that they | ||
are defined in, so there is no way for a malicious user to create Vaults | ||
out of thin air. A special Minter resource needs to be defined to mint | ||
new tokens. | ||
|
||
Implemented Interfaces: | ||
- `FungibleToken.Provider` | ||
- `FungibleToken.Receiver` | ||
- `FungibleToken.Balance` | ||
- `MetadataViews.Resolver` | ||
|
||
|
||
### Initializer | ||
|
||
```cadence | ||
func init(balance UFix64) | ||
``` | ||
|
||
|
||
## Functions | ||
|
||
### fun `withdraw()` | ||
|
||
```cadence | ||
func withdraw(amount UFix64): FungibleToken.Vault | ||
``` | ||
Function that takes an amount as an argument | ||
and withdraws that amount from the Vault. | ||
It creates a new temporary Vault that is used to hold | ||
the money that is being transferred. It returns the newly | ||
created Vault to the context that called so it can be deposited | ||
elsewhere. | ||
|
||
Parameters: | ||
- amount : _The amount of tokens to be withdrawn from the vault_ | ||
|
||
Returns: The Vault resource containing the withdrawn funds | ||
|
||
--- | ||
|
||
### fun `deposit()` | ||
|
||
```cadence | ||
func deposit(from FungibleToken.Vault) | ||
``` | ||
Function that takes a Vault object as an argument and adds | ||
its balance to the balance of the owners Vault. | ||
It is allowed to destroy the sent Vault because the Vault | ||
was a temporary holder of the tokens. The Vault's balance has | ||
been consumed and therefore can be destroyed. | ||
|
||
Parameters: | ||
- from : _The Vault resource containing the funds that will be deposited_ | ||
|
||
--- | ||
|
||
### fun `getViews()` | ||
|
||
```cadence | ||
func getViews(): [Type] | ||
``` | ||
The way of getting all the Metadata Views implemented by ExampleToken | ||
|
||
developers to know which parameter to pass to the resolveView() method. | ||
|
||
Returns: An array of Types defining the implemented views. This value will be used by | ||
|
||
--- | ||
|
||
### fun `resolveView()` | ||
|
||
```cadence | ||
func resolveView(_ Type): AnyStruct? | ||
``` | ||
The way of getting a Metadata View out of the ExampleToken | ||
|
||
Parameters: | ||
- view : _The Type of the desired view._ | ||
|
||
Returns: A structure representing the requested view. | ||
|
||
--- |
Oops, something went wrong.