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

fixed a couple of grammatical mistakes on the Basic Bank page #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions documentation/leo/11_basic_bank.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ title: A Basic Bank using Leo
This program implements a bank that issues tokens to users and allows users to deposit tokens to accrue simple interest on their deposits.

### User Flow

1. The bank issues users tokens via the `issue` function.
2. A user deposits tokens via the `deposit` function.
3. Upon a user's request to withdraw, the bank calculates the appropriate amount of compound interest and pays the user the principal and interest via the `withdraw` function.

Note that the program can be easily extended to include addition features such as a `transfer` function, which would allow users to transfer tokens to other users.
Note that the program can be easily extended to include additional features such as a `transfer` function, which would allow users to transfer tokens to other users.

## Bugs

You may have already guessed that this program has a few bugs. We list some of them below:
You may have already guessed that this program has a few bugs. We list some of them below:

- `withdraw` can only be invoked by the bank. A malicious bank could lock users' tokens by not invoking `withdraw`.
- `withdraw` fails if the sum of the interest and principal is greater than the user's balance.
- User's can increase their principal by depositing tokens multiple times, including immediately before withdrawl.
- `withdraw` fails if the sum of the interest and principal is greater than the user's balance.
- Users can increase their principal by depositing tokens multiple times, including immediately before withdrawl.
- Integer division rounds down; if the calculated interest is too small, then it will be rounded down to zero.

Can you find any others?

## Language Features and Concepts

- `record` declarations
- `assert_eq`
- core functions, e.g. `BHP256::hash`
Expand All @@ -48,10 +51,10 @@ The `.env` file contains a private key and address. This is the account that wil

## Walkthrough

* [Step 0: Issue Tokens](#issue)
* [Step 1: Deposit Tokens](#deposit)
* [Step 2: Wait](#wait)
* [Step 3: Withdraw Tokens](#withdraw)
- [Step 0: Issue Tokens](#issue)
- [Step 1: Deposit Tokens](#deposit)
- [Step 2: Wait](#wait)
- [Step 3: Withdraw Tokens](#withdraw)

## <a id="issue"></a> Issue Tokens

Expand Down Expand Up @@ -101,7 +104,7 @@ You'll see that the output contains a new private record belonging to the user w

With the 50 token deposit, let's say 15 periods of time pass with compounding interest at a rate of 12.34% on the principal amount.

You can run the calculation yourself, it comes out to 266 tokens accrued using those numbers.
You can run the calculation yourself, it comes out to 266 tokens accrued using those numbers.

## <a id="withdraw"></a> Withdraw Tokens

Expand All @@ -116,4 +119,4 @@ PRIVATE_KEY=APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD
leo run withdraw aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 50u64 1234u64 15u64
```

You'll see here the withdrawal function creates a new private record for the user containing all 266 withdrawn tokens, and then calls the finalize `withdraw` function with arguments (address, amount), which will update the public balance of the bank back to 0. The public mapping will be queryable on-chain.
You'll see here the withdrawal function creates a new private record for the user containing all 266 withdrawn tokens, and then calls the finalize `withdraw` function with arguments (address, amount), which will update the public balance of the bank back to 0. The public mapping will be queryable on-chain.