SaFi Bank Space : Smart Contracts documentation for Main and Pocket accounts

Object model

Module

Description

common.blocking.blocking

Contains parameters for block an account by client or bank which are included in both Main and Pocket account smart contracts. Also provides functions which return if current account is blocked by client or bank

common.debts.*

Owned by Loans squad, contains debt manager related code.

common.debugging.debug

Custom implementation which enables debugging for re-scheduling events in Smart Contract. In TM there is global parameter which enables features of this module (allowed_debug), which can contain values true|false. Contains debug instance level parameter which is included in Main and Pocket Smart contracts. When debug parameter is changed, then processing is in place. After scheduled event is processed, then schedules are fixed by this module.

common.features.transaction_limits

Implements logic for minimum balance. Is responsible for rejecting transactions which do not fit in the limit of minimum balance. Available checks are done on Addresses per account type and module is responsible for this behavior.

common.interests.interest_events

List of available events which are statically included in interests transactions based on type.

common.interests.interests

Module implementation for calculation of interests for Main and Pocket account types. Contains instance parameters definitions which are included in Main and Pocket Smart Contracts.

Implementation for executing interest accrual on schedules which can be:

  • daily

  • monthly

  • end of tenure

Handles interests for:

  • Main account

  • Unlocked pocket account

  • Locked pocket account

This module is also responsible for execution of

  • transactions when locked pocket is unlocked (revert bonus/tax etc.)

  • close pocket transactions - cleanup of all funds on account from all addresses based on specification

common.interests.interests_withdrawal

Allows withdrawal from interests addresses before Default address. Interest is used as part of Default address and when post posting code executes, then re-balancing is in place and used amount from Interest is moved to Default address.

common/interests/limited_interest.py

Function for calculation of interest based on given principal amount and interest rate. Includes global limitation of interest - all interests from principal above global interest limit are computed using reduced rate.

common.loans.*

Owned by Loans squad, contains loan related code.

common.pockets.utils

Function for getting available balance of Unlocked pocket. Used during repayment of the debt from pockets (Loans squad)

common.interest_rate

Module containing template parameters for interest rates and getters.

debt.*

Owned by Loans squad, contains debt manager related code.

internal_account.asset_account_contract

Empty (must) internal account smart uploaded to TM as a product with TSIDE=asset

internal_account.liability_account_contract

Empty (must) internal account smart uploaded to TM as a product with TSIDE=liability

main.features.overdraft

Implementation of overdraft usage in Main account Smart contract. Contains template parameters which defines:

  • what transaction types can use available Overdraft

  • what transaction type should have Repayment transaction

Above parameters are used to validation if outgoing(debit) posting can be paid from Overdraft address.

When Overdraft is used by some postings, then re-balancing is in place which sends funds from OVERDRAFT address to Default address of the account.

Handles also repayment of overdraft, when that posting is identified, then non used funds from Overdraft are returned to Default address of Main account.

main.main_account

Smart contract for main account. Uses:

  • blocking - Both customer and bank ones. If enabled rejects specific transactions.

  • interests - Daily accrual, monthly payment

  • overdraft

More information here. (TODO: add link)

main.types

Contains name of overdraft address. In future might contain other static names.

pocket.features.debt_balances

Contains method for available balance used in debt manager when taking debt from saving account.

pocket.features.locking

Contains instance parameters for locked saving account and methods used in end of tenure event.

pocket.features.own_transfer

Contains instance parameters and validation for outgoing transactions for saving accounts that allow only transfer to associated main account

pocket.features.pocket_type

Containd definition of instance parameters for saving pocket type (locked / unlocked)

pocket.pocket

Smart contract for saving account. Uses:

  • blocking - Both customer and bank ones. If enabled rejects specific transactions.

  • interests - Daily accrual, monthly payment

More information here. (TODO: add link)

pocket.types

Contains name definition of closing account transaction type.

workflows/send_revent.yaml

Definition of workflow that sends message to TMWorkflowInstanceCreate Kafka channel. This is just standard workaround how to achieve this. Workflows are in general deprecated. Replace with simple sending of event available in next version of TM.

Testing

There are two types of tests

  • unit tests - simple standard unit tests located near tested modules in test directory

  • simulation tests - tests defined by finance events (postings) and validation of balances at specified timestamps. Simulates everything in the vault including scheduled events.

(TODO: more?)

Deployment

(TODO)

Attachments: