# Data structure in our centralized system

This page explains the data structure of Velora's centralized service handling limit orders. It's adding some features like:

* tracking **maker** `balance` and `allowance` for ERC20 tokens.
* tracking state of orders

  * Fulfillment.
  * Cancellation.
  * Expiration.
  * Partially fulfillment.

For more information, please refer to the following document:

{% content-ref url="on-chain-data-structure" %}
[on-chain-data-structure](https://developers.velora.xyz/api/augustusrfq/on-chain-data-structure)
{% endcontent-ref %}

## ERC20: Order structure

```json
{
    "expiry": 0,
    "createdAt": 1661165141,
    "updatedAt": 1661165141,
    "transactionHash": null,
    "chainId": 137,
    "nonceAndMeta": "7433034152904838547212883274543254857465784035140417181410394112",
    "maker": "0x05182e579fdfcf69e4390c3411d8fea1fb6467cf",
    "taker": "0xdef171fe48cf0115b1d80b88dc8eab59176fee57",
    "takerFromMeta": "0x0000000000000000000000000000000000000000",
    "makerAsset": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
    "takerAsset": "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
    "makerAmount": "10000000000000000",
    "fillableBalance": "10000000000000000",
    "swappableBalance": "10000000000000000",
    "makerBalance": "10000000000000000",
    "takerAmount": "7775870000000000",
    "signature": "0x43dd8dbc8228594171d0ed3e633ca0eb5c24f46bf0575100623ae56723712f807ecaf7dc8edfcf0d4517f80f11bf016bde0a9a20e243eea2bb32e55eadbb6b0d1b",
    "orderHash": "0xdef400fd95d028d8caaba2c4887d2694563e0bc7f73c17d747feac2e24ed411d",
    "permitMakerAsset": null,
    "type": "LIMIT",
    "state": "PENDING"
}
```

### Difference with on-chain limit order

* `nonceAndMeta`: In our centralized system we force nonce and meta to be constructed from an address plus a random integer between `0` and `2 ^  53 - 1` shifted 160 bits. The address that we pack is the actual taker address. (The address that swap `takerAsset` to `maketAsset`)

```
nonceAndMeta = address + (randInt(0, 2 ^ 53 - 1) << 160)
```

* `takerFromMeta`: is the decoded taker from `nonceAndMeta`. In Augustus contract we check the actual `takerAddress` (The address who swap `takerAsset` to `makerAsset`) by extracting its value from `nonceAndMeta`.
* `fillableBalance`:  is the amount that remains to be filled and can be used to check if the amount is partially filled. (`fillableBalance` ≠ `makeAmount`)
* `swappableBalance`:  is the actual amount that can be filled at this time.
* `makerBalance`: max amount `makerAddress` can fill the limit order.
* `orderHash`: hash of the on-chain Data structure.
* permitMakerAsset: always null for now will be used to store permit.
* `type`: `P2P` / `LIMIT` differentiate `p2p` from normal orders
  * `P2P`: has `takerFromMeta` set to some specific address.
  * `LIMIT`: has `takerFromMeta` set to `0x....0`.
* `state`: `PENDING` / `FULFILLED` / `EXPIRED` / `CANCELLED`.
  * `PENDING`: order is still usable.
  * `FULFILLED`: order is fully fulfilled.
  * `EXPIRED`: order is expired.
  * `CANCELLED`: order is canceled.

## NFT ERC 20/721/1155 Order structure

```
{
    "expiry": 1664716033,
    "createdAt": 1663853026,
    "transactionHash": null,
    "chainId": 137,
    "nonceAndMeta": "6696393496368457207383969069655254624825140823245405670718046208",
    "maker": "0x05182e579fdfcf69e4390c3411d8fea1fb6467cf",
    "taker": "0x0000000000000000000000000000000000000000",
    "takerFromMeta": "0x0000000000000000000000000000000000000000",
    "makerAsset": "0xcd494673999194365033d7a287af9f0a3b163874",
    "makerAssetId": "1027",
    "makerAssetType": 2,
    "takerAsset": "0xad6d458402f60fd3bd25163575031acdce07538d",
    "takerAssetId": "0",
    "takerAssetType": 0,
    "makerAmount": "1",
    "fillableBalance": "1",
    "takerAmount": "50",
    "signature": "0x762dd1eb9447d10a24adff2c16dd2a6a4f6abdeff2e51fc1df0428129e4b7c1a00100a35f936e591956a5c86d3d502ecb591134bc8c0f32f12fd7533c199975e1c",
    "orderHash": "0xe40182a75563c4c84e2ff4f2b4b44045fc94f66c929780ee82560d30cbadeb83",
    "permitMakerAsset": null,
    "type": "LIMIT",
    "state": "PENDING"
}

```

#### Difference with on-chain NFT order

* `makerAsset`: is the decoded address of the `makerAsset` from our limit order contract.
* `makerAssetId`: is the decoded token type from the `makerAsset` from our limit order contract.
* `takerAsset`: is the decoded address of the `makerAsset` from our limit order contract.
* `takerAssetId`: is the decoded token type from the `takerAsset` from our limit order contract.
* `takerFromMeta`: is the decoded taker from `nonceAndMeta`. In Augustus contract we check the actual `takerAddress` (The address who swap `takerAsset` to `makerAsset`) by extracting its value from `nonceAndMeta`.
* `fillableBalance`:  is the amount that remains to be filled and can be used to check if the amount is partially filled. (`fillableBalance` ≠ `makeAmount`)
* `orderHash`: hash of the on-chain Data structure.
* permitMakerAsset: always null for now will be used to store permit.
* `type`: `P2P` / `LIMIT` differentiate `p2p` from normal orders
  * `P2P`: has `takerFromMeta` set to some specific address.
  * `LIMIT`: has `takerFromMeta` set to `0x....0`.
* `state`: `PENDING` / `FULFILLED` / `EXPIRED` / `CANCELLED`.
  * `PENDING`: order is still usable.
  * `FULFILLED`: order is fully fulfilled.
  * `EXPIRED`: order is expired.
  * `CANCELLED`: order is canceled.
