I added the fixes to my "Simple Term Deposit AT" and I tested it on my local testnet - seems working.
It blocks the funds for N months
When the goal is met, it starts re-paying 1/N each 30 days.
^declare state
^declare interest_decision
^declare target_amount
^declare months
^declare month_in_blocks
SLP $interest_decision
FUN @current_amount get_Current_Balance
BGE $current_amount $target_amount :repayment
FUN @timestamp get_Creation_Timestamp
refund_loop:
FUN A_to_Tx_after_Timestamp $timestamp
FUN @tx_info check_A_Is_Zero
BZR $tx_info :not_funded
FUN @tx_amount get_Amount_for_Tx_in_A
FUN @timestamp get_Timestamp_for_Tx_in_A
FUN B_to_Address_of_Tx_in_A
FUN send_to_Address_in_B $tx_amount
JMP :refund_loop
repayment:
FUN @monthly_payout get_Current_Balance
DIV @monthly_payout $months
FUN B_to_Address_of_Creator
SET @state #0000000000000002
repayment_loop:
SLP $month_in_blocks
FUN @current_amount get_Current_Balance
BGE $monthly_payout $current_amount :end
FUN send_to_Address_in_B $monthly_payout
JMP :repayment_loop
not_funded:
SET @state #0000000000000001
FUN B_to_Address_of_Creator
JMP :end_loop
end:
FUN B_to_Address_of_Creator
SET @state #0000000000000003
end_loop:
FUN send_All_to_Address_in_B
JMP :end_loop
Assembly
250100000035000405000000210500000002000000423501030600000033040306000000352501070000001b07000000653506030800000035070306000000320a03330204080000001a1d00000035000409000000090900000003000000320b03010000000002000000000000002504000000350004050000002109000000050000002b330204090000001a6e00000001000000000100000000000000320b031ab5000000320b03010000000003000000000000003203041ab5000000
Data
0000000000000000DDDDDDDDDDDDDDDDTTTTTTTTTTTTTTTTMMMMMMMMMMMMMMMM302a000000000000
D - Interest decision time in blocks
T - Target amount
M - number of months to run
Example:
For blocking 1,000,000 five years for 5% per year (1000000*1.05^5 = 1276281)
0000000000000000a01700000000000080e101b5137400003c00000000000000302a000000000000
Please, who can, recheck it.
Currently I don't have now time to change the crowdfund.html for this script.
I have also tested the code in both burst and qora and in both platform works as expected. The only "mistake" I found is the amount.
1000000*1.05^5 = 1276281.5625 but the hex you have ( 80e101b513740000 -> 00007413b501e180 ) equals with 1276279 and not 1276281
Nice work