Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accounting needs #4770

Open
damip opened this issue Nov 4, 2024 · 0 comments
Open

Accounting needs #4770

damip opened this issue Nov 4, 2024 · 0 comments
Labels
EllipX Project w/ Mark K. p1

Comments

@damip
Copy link
Member

damip commented Nov 4, 2024

We need to provide the following a grpc stream that gives all MAS, DEFERRED_MAS, ROLL movements for all addresses but with an optional per-address filter. This includes the following types of transfers, and only applies to final movements:

  • a roll auto-sell of 1200 rolls would contribute the following two entries:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",  // made of the concatenation of the execution trail hash, ":" as separator, and the index of the coin transfer in the current slot
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "ROLL",
        "prev_amount": "1200",
        "amount": "1200",
        "post_amount": "0",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "ROLL_AUTOSELL"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",  // made of the concatenation of the execution trail hash, ":" as separator, and the index of the coin transfer in the current slot
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "CREDIT",
        "item": "DEFERRED_MAS",
        "prev_amount": "0",
        "amount": "120000",
        "post_amount": "120000",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "ROLL_AUTOSELL"
    }
]
  • a deferred credit of 123.25 being credited back as MAS would contribute:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "DEFERRED_MAS",
        "prev_amount": "123.25",
        "amount": "123.25",
        "post_amount": "0",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "DEFERRED_CREDIT"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "CREDIT",
        "item": "MAS",
        "prev_amount": "1000",
        "amount": "123.25",
        "post_amount": "1123.25",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "DEFERRED_CREDIT"
    }
]
  • deferred calls being executed: we look at the ledger balance deltas caused by the execution. Example:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "1",
        "post_amount": "99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "DEFERRED_CALL",
        "deferred_call_id": "fsd54fs65df4sd65fd56sfsdf6sd6fds",
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU6s5dfsd5f65sdf6ds4f6dssd5sdf",
        "direction": "CREDIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "1",
        "post_amount": "101",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "DEFERRED_CALL",
        "deferred_call_id": "fsd54fs65df4sd65fd56sfsdf6sd6fds",
    }
]
  • at the beginning of a block execution:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",  // block producer
        "direction": "CREDIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "123.25",
        "post_amount": "223.25",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "BLOCK_REWARD",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU65sd4654ds86s7dsd68sdsd54", // endorser
        "direction": "CREDIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "123.25",
        "post_amount": "223.25",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "ENDORSEMENT_REWARD",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "endorsement_id": "E6s5df4sd65fsd8f7ze98fze6f4z5e"
    },
    [... other endorsers]
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:10",
        "address": "AUs65df4s6dfsd65f4sd65fsd5f6ds65",  // endorsed address
        "direction": "CREDIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "123.25",
        "post_amount": "223.25",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "ENDORSED_REWARD",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "endorsement_id": "E6s5df4sd65fsd8f7ze98fze6f4z5e"
    },
]
  • in case denunciations are present in the block
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "ROLL",
        "prev_amount": "100",
        "amount": "1",
        "post_amount": "99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "SLASH",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "denunciation_details": {
            "target_slot": {"period": "42243", "thread": "1"},
            "target_type": "BLOCK", // or Endorsement
            "target_id1": "[...first block or endorsement ID...],
            "target_id2": "[...second block or endorsement ID...],
        }
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU544df65sd4f65sd4f6df65ds65s",
        "direction": "DEBIT",
        "item": "DEFERRED_MAS", // for this address there were no rolls so we slashed deferred MAS
        "prev_amount": "1100",
        "amount": "100",
        "post_amount": "1000",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "SLASH",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "denunciation_details": {
            "target_slot": {"period": "42243", "thread": "3"},
            "target_type": "ENDORSEMENT",
            "target_id1": "[...first block or endorsement ID...],
            "target_id2": "[...second block or endorsement ID...],
        }
    }
]
  • when executing a roll_buy operation:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "1000",  // cost of the roll buy
        "amount": "400",
        "post_amount": "600",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_ROLL_BUY_COINS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "600",  // fees of the roll buy
        "amount": "0.01",
        "post_amount": "599.99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_ROLL_BUY_FEE",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:2",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "CREDIT",
        "item": "ROLL",
        "prev_amount": "5", 
        "amount": "4",
        "post_amount": "9",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_ROLL_BUY_ROLLS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
]
  • when executing a roll_sell operation:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "ROLL",
        "prev_amount": "5",
        "amount": "1",
        "post_amount": "4",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_ROLL_SELL_ROLLS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "600",  // fees of the roll buy
        "amount": "0.01",
        "post_amount": "599.99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_ROLL_BUY_FEE",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:2",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "CREDIT",
        "item": "DEFERRED_MAS",
        "prev_amount": "0", 
        "amount": "100",
        "post_amount": "100",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_ROLL_SELL_DEFERRED_MAS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
]
  • when executing an execute_sc operation:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "600",
        "amount": "0.01",
        "post_amount": "599.99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_EXECUTESC_FEE",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    
    [.. here any debits or credits caused by the execution ..]
]
  • when executing an call_sc operation:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",  // debit callsc coins
        "item": "MAS",
        "prev_amount": "1000",
        "amount": "400",
        "post_amount": "600",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_CALLSC_COINS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AS5dsf4s5d6f4sdfdsfsd65fsdf4s5df87sdfs",
        "direction": "CREDIT",  // credit callsc coins to target smart contract
        "item": "MAS",
        "prev_amount": "100",
        "amount": "400",
        "post_amount": "500",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_CALLSC_COINS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:2",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "600",
        "amount": "0.01",
        "post_amount": "599.99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_CALLSC_FEE",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    
    [.. here any debits or credits caused by the execution ..]
]
  • when executing a transaction operation:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "1000",
        "amount": "400",
        "post_amount": "600",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_TRANSACTION_COINS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU5dsf4s5d6f4sdfdsfsd65fsdf4s5df87sdfs",
        "direction": "CREDIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "400",
        "post_amount": "500",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_TRANSACTION_COINS",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:2",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "600",
        "amount": "0.01",
        "post_amount": "599.99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "OP_TRANSACTION_FEE",
        "block_id": "B5sdf45sd45fsd5fsd8fsd6fd45s4fds",
        "operation_id:": "Osdfs6dfs65df4sdf4s65df4sd56f"
    },
    
    [.. here any debits or credits caused by the execution ..]
]
  • async messages being executed: we look at the ledger balance deltas caused by the execution. Example:
[
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:0",
        "address": "AU654d6f54sd65f4s65d4f65sd65fdss6",
        "direction": "DEBIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "1",
        "post_amount": "99",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "ASYNC_MSG",
        "async_msg_id": "fsd54fs65df4sd65fd56sfsdf6sd6fds",
    },
    {
        "id": "0x782892E9898DS89D98QS98DSQ9898:1",
        "address": "AU6s5dfsd5f65sdf6ds4f6dssd5sdf",
        "direction": "CREDIT",
        "item": "MAS",
        "prev_amount": "100",
        "amount": "1",
        "post_amount": "101",
        "timestamp": "65465645646",
        "slot": {"period": "42245", "thread": "2"},
        "origin": "ASYNC_MSG",
        "async_msg_id": "fsd54fs65df4sd65fd56sfsdf6sd6fds",
    }
]
@SlnPons SlnPons added EllipX Project w/ Mark K. p1 labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EllipX Project w/ Mark K. p1
Projects
None yet
Development

No branches or pull requests

2 participants