Rafiki uses a combination of liquidity (credit) and settlement (debit) accounts to perform double-entry accounting.
In this context, accounts in Rafiki are specifically the accounts that peers hold with one another. These are not customer accounts. This distinction is crucial for understanding how Rafiki handles transactions and settlements.
A settlement account holds a non-positive balance, with Rafiki ensuring that total credits do not exceed total debits. A settlement account represents the total funds you as the ASE have deposited into Rafiki.
Before you can peer with another ASE, you must both agree on the asset you will use for settlement. The Interledger packets exchanged between you and your peer will be denominated in the agreed-upon asset.
An asset represents an item of value that can be transferred via the Interledger Protocol. Since the Interledger Protocol aims to create an internet of value, it allows for the transfer of any asset, not just currency. In practice, however, assets are usually denominated in a currency (fiat or branded currencies).
In Rafiki, the asset type is comprised of the following properties.
TigerBeetle is a high-performance distributed financial accounting database used by Rafiki’s backend service to store account balance data at the ILP layer. Both liquidity and settlement accounts in Rafiki correspond to TigerBeetle credit and debit accounts, respectively. TigerBeetle only holds balance data without any additional ILP packet metadata. For detailed information on TigerBeetle, including its consensus mechanism and its limitations, visit the official TigerBeetle documentation and blog.
You have the flexibility to choose whether to use TigerBeetle or opt for a separate Postgres database. However, TigerBeetle is recommended due to its speed, efficiency, and dedicated design for handling double ledger accounting. For more information about Tigerbeetle in a production environment, see Running Rafiki in production.
Asset liquidity represents the value, denominated in a given asset, that Rafiki has at its disposal in which to send or forward ILP packets. Asset liquidity increases when packets are received and decreases when packets are sent. Asset liquidity is always positive and cannot fall below zero.
Additionally, you must provide asset liquidity if you are exchanging one currency for another. Asset liquidity ensures there is enough value available to handle transactions in the specified assets.
You should define and adjust asset liquidity based on your liquidity risk profile.
Your Rafiki instance is configured with two assets: EUR and USD. You’ve set both to have an asset scale of 0. Your EUR liquidity is 10, and your USD liquidity is 50.
In a cross currency transaction:
Rafiki receives packets worth 10 EUR and sends packets worth 11 USD. Your EUR liquidity increases to 20 (10 + 10) and your USD liquidity decreases to 39 (50 - 11).
Rafiki receives packets worth 50 EUR which equates to 55 USD. This transaction fails because Rafiki does not have enough USD liquidity.
Peer liquidity is the credit line, denominated in the asset of the peering relationship, you extend to a peer. Peer liquidity should be defined in the peering agreement and depends on the trust between you and your peer. If peer liquidity is insufficient, payments will not be processed. When peer liquidity is used up, you and your peer should settle then reset your liquidity.
Your peer, Cloud Nine Wallet, has a peer liquidity of 100 USD. Rafiki can send packets that total up to 100 USD to wallet addresses issued by Cloud Nine Wallet.
After the 100 USD liquidity is used up, you settle with Cloud Nine Wallet and reset the peer liquidity in Rafiki to 100 USD.
Payment liquidity is managed for incoming and outgoing payments created via Open Payments through liquidity accounts in your accounting database. When incoming or outgoing payments are created via the Open Payments APIs, a corresponding liquidity account is automatically created. Liquidity must be deposited to an outgoing payment account before the payment can be processed. You are notified to deposit or withdraw liquidity via webhook events.
Transfers in Rafiki are based on double-entry accounting, increasing both the total debits (withdrawals )of one account and the total credits (deposits) of another by the same amount.
Example: Sender creates an outgoing payment for 100 USD to an incoming payment at a peer’s Rafiki instance. The peering relationship is in USD.
USD outgoing payment liquidity acct
USD peer liquidity acct
Debit
Credit
100
Debit
Credit
100
Cross currency
Debit Account
Credit Account
Asset
Outgoing payment
Asset liquidity
USD
Asset Liquidity
Peer Liquidity
EUR
Example: Sender creates an outgoing payment for 100 USD to an incoming payment at a peer’s Rafiki instance. The peering relationship is in EUR, so payment is converted on the sending side.
Example: An incoming payment receives 100 USD from an outgoing payment at a peer’s Rafiki instance.
USD peer liquidity acct
USD incoming payment liquidity acct
Debit
Credit
100
Debit
Credit
100
Same asset in Simple Payment Setup Protocol (SPSP) / Web Monetization
Debit Account
Credit Account
Peer liquidity
Wallet address
Example: A wallet address receives 2 USD from an ILP payment at a peer’s Rafiki instance.
USD peer liquidity acct
USD wallet address liquidity acct
Debit
Credit
2
Debit
Credit
2
Cross currency
Debit Account
Credit Account
Asset
Peer liquidity
Asset liquidity
USD
Asset liquidity
Incoming payment
EUR
Example: A Rafiki instance receives 10 USD from a peer (peering relationship in USD) to be deposited in an incoming payment liquidity account denominated in EUR. The payment is converted to EUR and deposited.
USD peer liquidity acct
USD asset liquidity acct
Debit
Credit
10
Debit
Credit
10
EUR asset liquidity acct
EUR incoming payment liquidity acct
Debit
Credit
9
Debit
Credit
9
Cross-currency in Simple Payment Setup Protocol (SPSP) / Web Monetization
Debit Account
Credit Account
Asset
Peer liquidity
Asset liquidity
USD
Asset liquidity
Wallet address
EUR
Example: A Rafiki instance receives 10 USD from a peer (peering relationship in USD) to be deposited in a wallet address liquidity account denominated in EUR. The payment is converted to EUR and deposited.