pallet-bank

Crates.iopallet-bank
lib.rspallet-bank
version0.1.4
sourcesrc
created_at2023-07-06 14:26:00.225644
updated_at2023-07-17 16:06:02.458271
descriptionFRAME pallet bank for handling financial systems of investment, loans, etc.
homepagehttps://github.com/abhi3700/substrate-playground/pallets/bank
repositoryhttps://github.com/abhi3700/substrate-playground/
max_upload_size
id909948
size62,778
Abhijit Roy (abhi3700)

documentation

README

Bank Pallet

A pallet for handling financial systems of investment, loans, etc.

  • [Config]
  • [Call]

Overview

Anyone can open FD (Fixed Deposit) by reserving some amount of currency with allowed maturity period. The FD principal amount has to be within the range of min_fd_amount & max_fd_amount (set by admin). The FD amount is reserved from the user's free_balance.

During the FD period, the reserved amount cannot be used that's why need to be freed from the free_balance. In order to receive interest, FD can only be closed after the fd_epoch (set by admin) is elapsed, else the reserved amount is returned to the user without any interest as per the premature withdrawal facility and a penalty (0.5-1%) is charged. The penalty_rate is data persistent & set by the root origin.

But, if the FD is closed after individual FD vault's maturity_period (set during opening), then the reserved amount is returned to the user with accrued interest. The interest_rate is stored & set by the root origin.

The accrued interest comes from a treasury 💎 account which is funded by the root origin. And the treasury account is funded via network's inflation or balance slashing of the user in case of malicious activity.

NOTE: The runtime must include the Balances pallet to handle the accounts and balances for your chain. It has been shown as a [dev-dependencies] in the Cargo.toml file.

Interface

Dispatchable Functions

  • set_fd_params
  • set_treasury
  • open_fd
  • close_fd
  • lock_for_membership
  • unlock_for_membership

Build

Check if the dependencies are working properly:

$ cargo check -p node-template-runtime

Build the runtime's WASM binary with the following command:

$ cargo build -r

Test

To run all the tests in a pallet:

$ cargo test -p pallet-bank

To run the individual test:

# example
$ cargo test -p pallet-bank --lib -- tests::it_works_for_default_value

Although there is a button shown above to run individual test in VSCode.

Benchmark

Run

Run a relaychain node (w/o debug mode):

$ ./target/release/node-template --dev

In debug mode, run a relaychain node:

$ RUST_LOG=runtime=debug ./target/release/node-template --dev
Commit count: 53

cargo fmt