Ledger Entry and Exit Flow

As Midaz uses a double-entry system by design, the input and output values of the Ledger must be recorded through the @external/{{instrumentCode}} account, which represents contact with the outside world. For example, in a PIX-out transaction from Account A at Bank A to Account B at Bank B, the flow is as follows:

OriginDestinationValue

@accountId bank A

@external/BRL bank A

[BRL 0 1000]

@external/BRL bank B

@accountId bank B

[BRL 0 1000]

In other words, [BRL 0 1000] is sent from Account A of Bank A to the @external/BRL account of Bank A. The flow in the Ledger of Bank A stops there, and the transaction is settled via SPI (in the case of a PIX transaction). Then, Bank B receives a notification to credit Account B, and the amount is moved from the @external/BRL account of Bank B to the PIX destination account.

During the balance movement flow, assuming Bank A only has Account A and Bank B only has Account B, the balances update as follows:

AccountPrevious BalanceAmountFinal Balance

@accountId Bank A

1000

-1000

0

@external/BRL Bank A

0

+1000

+1000

@external/BRL Bank B

0

-1000

-1000

@accountId bank B

0

+1000

1000

The @external/{{instrumentCode}} account can have a negative or zero balance but never a positive balance, which would indicate that more assets were sent than exist in the ledger. Its balance will always be equal to the negative sum of all ledger account balances.

When creating instruments, if the @external/{{instrumentCode}} account does not exist, it is always created.

Last updated