Skip to content
Draft
32 changes: 32 additions & 0 deletions serializations.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ ambiguity.
| 4 | oracle |
| 5 | contract |
| 6 | channel |
| 7 | token |

In Erlang notation, the `id()` type pattern is:
```
Expand Down Expand Up @@ -252,6 +253,7 @@ subsequent sections divided by object.
| Sophia byte code | 70 |
| Generalized accounts attach transaction | 80 |
| Generalized accounts meta transaction | 81 |
| Tokens | 90 |
| Key block | 100 |
| Micro block | 101 |
| Light micro block | 102 |
Expand Down Expand Up @@ -282,6 +284,14 @@ subsequent sections divided by object.
]
```

#### Accounts (version 4, Normal accounts with flags and tokens, from XXX release)
```
[ <flags> :: int()
, <nonce> :: int()
, <balance> :: int()
, <tokens> :: [{id(),int()}]
```

### Signed transaction
```
[ <signatures> :: [binary()]
Expand Down Expand Up @@ -309,6 +319,28 @@ The recipient must be one of the following:
* A contract identifier.
* A name identifier, whose related name entry has an identifier as value of pointer with key `account_pubkey`.
If multiple pointer entries are present for such key, then the first of such entries is used.
`

### Spend token transaction
```
[ <sender> :: id()
, <recipient> :: id()
, <token> :: id()
, <amount> :: int()
, <fee> :: int()
, <ttl> :: int()
, <nonce> :: int()
, <payload> :: binary()
]
```

The recipient must be one of the following:
* An account identifier.
* An oracle identifier.
* A contract identifier.
* A name identifier, whose related name entry has an identifier as value of pointer with key `account_pubkey`.
If multiple pointer entries are present for such key, then the first of such entries is used.
`

#### Oracles
```
Expand Down
72 changes: 72 additions & 0 deletions tokens/tokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Native Tokens

A native tokens is made up of two parts: a Native token type and a native token balance.

Native tokens types are a first class object on the chain that defines the
behaviour of a type of tokens. Native tokens live in their own account balances
of accounts.

Native tokens (from now on just tokens) are:
- Transferable (`spend`, `trade`)
- Countable
- Mintable (`mint`)
- Destroyable (`burn`)

Token types are:
- Creatable


## Token transactions

There is one transaction on token types:
- create

There are five token transactions:
- mint
- spend
- trade
- burn
- finalize

Other transactions that takes a balance can also take a native token balance.

### token create transaction

The token create transaction takes the following argument
- Meta data : string
and the followin optional arguments
- Contract
- Amount
- Recipient
- Parent
- Final

The `meta data` is an uniterpreted string but token minters are encouraged to
use the following json object:
{
"type" : "object",
"properties": {
"name": {"type" : "string"},
}
}

The `contract` has to provide the following ACI:
spend(recipient : address, payload : Type) : boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the payload type here? A binary string, I guess, like in normal spend?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it probably could be something ABI encoded. Just as in oracles. 🤔

trade([(from : address, to: address, Optional(token : address))], payload : Type)
mint(amount: integer)
burn(amount : integer) : boolean

The `amount` is the number of tokens to create.

The `recipient` an account to dump the tokens created, if not given the tokens are
spent to the creators account.

The `parent` is a pointer to a parent token for hierarchical tokens.

The `final` argument sets the final flag which would block future minting.

If a contract is provided then any transaction (spend, trade, mint, burn) would
call this contract and the transaction only goes through if the result of the
corresponfing contract call returns true. Any other transaction using
the token (such as contract call) would only be ececuted if a call to spend
returns true.