SaFi Bank Space : Saving pocket - interest computation

Smart contract setup

Parameters:

  • unlocked_interest_rate

  • locked_interest_rate

  • interest_tax_rate - global parameter for all products (also in main account)

Flags:

  • locked

Addresses:

  • default - customer's money

  • interest

    • unlocked pocket: interests accumulated on daily basis

    • locked pocket: used to simulate unlocked pocket's interests

  • monthly_interests

    • unlocked pocket: interests accumulated on monthly basis

    • locked pocket: used to simulate monthly transfer of interests of unlocked pocket in its simulation

  • locked_unlocked_diff - locked pocket interests lowered by simulated interests of unlocked pocket

Daily scheduled interests accumulation

  1. Compute unlocked_daily_interest = (default address + monthly_interests address) * unlocked_interest_rate.

  2. Transfer unlocked_daily_interest pesos from internal account to interest address.

  3. If pocket is locked, transfer (default * locked_interest_rate - unlocked_daily_interest) pesos from internal account to locked_unlocked_diff address.

  4. If it is end of month, transfer all money from interest address to

    • default address if pocket is unlocked

    • monthly_interests if pocket is locked

  5. If the pocket is locked and it is target day, transfer all money from non-default addresses to default address

Operations with the pocket

Transform locked to unlocked

  1. Transfer all money from locked_unlocked_diff address back to internal account

  2. Transfer all money from monthly_interests address to interests address

  3. Transfer all money from interests address to default address

Transform unlocked to locked

  1. Transfer all money from interests address to default address

Taxation

General rule is if any interest is moved to default account, the tax should be paid. Specifically:

  • In case of unlocked pocket, in the end of month when money is transferred from interest address

  • In case of locked pocket, on target day when money is transferred from all non-default addresses. Should be single transaction

  • When locked account is transformed to unlocked and money is transferred from monthly_interests address (TBD case of interests address)

  • (TBD) When unlocked account is transformed to locked and money is transferred from interests address.

Displayed balances

  • Money on the pocket = default address

  • Acquired unpaid interests = interests address + monthly_interests address + locked_unlocked_diff address

  • Money lost when transforming from locked to unlocked = locked_unlocked_diff address

Example of unlocked pocket

initial deposit: 100

days in month : 5 (just to shorten example)

unlocked_interest_rate = 0.02

day

default address

interests address

0

100

0

1

100

2 (+2)

2

100

4 (+2)

3

100

6 (+2)

4

100

8 (+2)

5

110

0 (+2, 10 moved to default)

6

110

2.2 (+2.2)

7

110

4.4 (+2.2)

8

110

6.6 (+2.2)

9

110

8.8 (+2.2)

10

121

0 (+2.2, 11 moved to default)

Note: other addresses are 0 all the time

Example of locked pocket

initial deposit: 100

days in month : 5 (just to shorten example)

unlocked_interest_rate = 0.02

locked_interest_rate = 0.05

locked until day 12

day

default address

interests address

monthly_interests address

locked_unlocked_diff address

Amount if transformed to unlocked (sum of first three columns)

Total amount in account

0

100

0

0

0

100

100

1

100

2 (+2 + 0)

0

3 (+5 - 2)

102

105

2

100

4 (+2 + 0)

0

6 (+5 - 2)

104

110

3

100

6 (+2 + 0)

0

9 (+5 - 2)

106

115

4

100

8 (+2 + 0)

0

12 (+5 - 2)

108

120

5

100

0 (+2, 10 moved ->)

10

15 (+5 - 2)

110

125

6

100

2.2 (+2 + 0.2)

10

17.8 (+5 -2.2)

112.2

130

7

100

4.4 (+2 + 0.2)

10

20.6 (+5 -2.2)

114.4

135

8

100

6.6 (+2 + 0.2)

10

23.4 (+5 -2.2)

116.6

140

9

100

8.8 (+2 + 0.2)

10

26.2 (+5 -2.2)

118.8

145

10

100

0 (+2 + 0.2, 11 moved ->)

21

29 (+5 -2.2)

121

150

11

100

2.42 (+2 +0.42)

21

31.58 (+5 -2.42)

123.42

155

12

160

0 (+2 +0.42, 4.84 moved to default)

0 (21 moved to default)

0 (+5 -2.42, 34.16 moved to default)

-

160

Comments

  • No “virtual” money

  • You can easily answer how many would customer lose in case of unlocking

  • In case of locked pocket, you can get money from two separate internal accounts, so you can also see the range of interest that has to be paid (first account contains money of interest that has to be paid for sure, second only if everybody will keep their pocket locked)

  • Unlocking can even be made so everything will be exactly as if you had unlocked pocket from the beginning, including interest that has to be paid at the end of the month