Skip to content
Draft
90 changes: 90 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,12 @@ subsequent sections divided by object.
| Sophia byte code | 70 |
| Generalized accounts attach transaction | 80 |
| Generalized accounts meta transaction | 81 |
| Token | 90 |
| Token create transaction | 91 |
| Token mint transaction | 92 |
| Token trade transaction | 93 |
| Token burn transaction | 94 |
| Token finalize transaction | 95 |
| Key block | 100 |
| Micro block | 101 |
| Light micro block | 102 |
Expand Down Expand Up @@ -282,6 +289,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 +324,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 From the XXX release
```
[ <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 Expand Up @@ -1013,3 +1050,56 @@ NOTE:
, <pubkey> :: binary()
]
```


#### Token create transaction
```
[ <creator> :: id()
, <meta_data> :: binary()
, <contract> :: id()
, <amount> :: int()
, <recipient> :: id()
, <parent> :: id()
, <final> :: bool()
, <ttl> :: int()
, <fee> :: int()
, <nonce> :: int()
]
```

#### Token mint transaction
```
[ <amount> :: int()
, <recipient> :: id()
, <final> :: bool()
, <ttl> :: int()
, <fee> :: int()
, <nonce> :: int()
]
```

#### Token trade transaction
```
[ <trades> :: [{id(), id(), int(), id()}]
, <ttl> :: int()
, <fee> :: int()
, <nonce> :: int()
]
```

#### Token burn transaction
```
[ <amount> :: int()
, <ttl> :: int()
, <fee> :: int()
, <nonce> :: int()
]
```

#### Token finalize transaction
```
[ <ttl> :: int()
, <fee> :: int()
, <nonce> :: int()
]
```
99 changes: 99 additions & 0 deletions tokens/tokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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 following optional arguments
- Contract
- Amount
- Recipient
- Parent
- Final

The `meta data` is an uninterpreted 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.

## Tokens state tree

The tokens state tree contain token type objects.
Tokens are stored in the account state tree as a list of tuples of
token id:s and balances.

### Token state tree objects

- The token state tree contains
- Token type objects

#### The token type object

- Created by an token create transaction.

```
{ creator :: id()
, <meta_data> :: binary()
, <contract> :: id()
, <total_amount> :: int()
, <parent> :: id()
, <final> :: bool()

}
```