-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdonate.tyron.scilla
118 lines (104 loc) · 7.24 KB
/
donate.tyron.scilla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
(* v1.5.0
donate.ssi dApp: Decentralised $ZIL Wallet for the SSI Community Donations
Self-Sovereign Identity Protocol
Copyright Tyron Mapu Community Interest Company 2023. All rights reserved.
You acknowledge and agree that Tyron Mapu Community Interest Company (Tyron) own all legal right, title and interest in and to the work, software, application, source code, documentation and any other documents in this repository (collectively, the Program), including any intellectual property rights which subsist in the Program (whether those rights happen to be registered or not, and wherever in the world those rights may exist), whether in source code or any other form.
Subject to the limited license below, you may not (and you may not permit anyone else to) distribute, publish, copy, modify, merge, combine with another program, create derivative works of, reverse engineer, decompile or otherwise attempt to extract the source code of, the Program or any part thereof, except that you may contribute to this repository.
You are granted a non-exclusive, non-transferable, non-sublicensable license to distribute, publish, copy, modify, merge, combine with another program or create derivative works of the Program (such resulting program, collectively, the Resulting Program) solely for Non-Commercial Use as long as you:
1. give prominent notice (Notice) with each copy of the Resulting Program that the Program is used in the Resulting Program and that the Program is the copyright of Tyron; and
2. subject the Resulting Program and any distribution, publication, copy, modification, merger therewith, combination with another program or derivative works thereof to the same Notice requirement and Non-Commercial Use restriction set forth herein.
Non-Commercial Use means each use as described in clauses (1)-(3) below, as reasonably determined by Tyron in its sole discretion:
1. personal use for research, personal study, private entertainment, hobby projects or amateur pursuits, in each case without any anticipated commercial application;
2. use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization or government institution; or
3. the number of monthly active users of the Resulting Program across all versions thereof and platforms globally do not exceed 10,000 at any time.
You will not use any trade mark, service mark, trade name, logo of Tyron or any other company or organization in a way that is likely or intended to cause confusion about the owner or authorized user of such marks, names or logos.
If you have any questions, comments or interest in pursuing any other use cases, please reach out to us at [email protected].*)
scilla_version 0
import PairUtils BoolUtils ListUtils IntUtils
library Donate
let one_msg =
fun( msg: Message ) =>
let nil_msg = Nil{ Message } in Cons{ Message } msg nil_msg
let zero = Uint128 0
let zeroByStr20 = 0x0000000000000000000000000000000000000000
let option_value = tfun 'A => fun( default: 'A ) => fun( input: Option 'A) =>
match input with
| Some v => v
| None => default end
let option_uint128_value = let f = @option_value Uint128 in f zero
let option_bystr20_value = let f = @option_value ByStr20 in f zeroByStr20
let hundred = Uint128 100
let ten = Uint128 10
let eighty = Uint128 80
let wfp = "wfp"
let insurance = "insurance"
let coop = "tyron"
type Beneficiary =
| NftUsername of String String (* username & domain *)
| Recipient of ByStr20
contract DonateDApp(
init: ByStr20 with contract field dApp: ByStr20 with contract
field dns: Map String ByStr20 end end,
xpoints_init: Map ByStr20 Uint128
)
field version: String = "donate--1.5.0"
field xpoints: Map ByStr20 Uint128 = xpoints_init
field donations: Map String Uint128 = Emp String Uint128
field ledger_time: BNum = BNum 0
field tx_number: Uint128 = zero
procedure Timestamp()
current_block <- &BLOCKNUMBER; ledger_time := current_block;
latest_tx_number <- tx_number;
new_tx_number = let incrementor = Uint128 1 in builtin add latest_tx_number incrementor; tx_number := new_tx_number end
(* Receive $ZIL native funds *)
transition AddFunds()
accept;
get_xpoints <- xpoints[_origin]; x_points = option_uint128_value get_xpoints;
new_bal = builtin add x_points _amount; xpoints[_origin] := new_bal;
percent = builtin div _amount hundred; wfp_ = builtin mul percent ten; insurance_ = builtin mul percent ten; coop_ = builtin mul percent eighty;
get_wfp_bal <- donations[wfp]; wfp_bal = option_uint128_value get_wfp_bal; new_wfp = builtin add wfp_bal wfp_;
donations[wfp] := new_wfp;
get_insurance_bal <- donations[insurance]; insurance_bal = option_uint128_value get_insurance_bal; new_insurance = builtin add insurance_bal insurance_;
donations[insurance] := new_insurance;
get_coop_bal <- donations[coop]; coop_bal = option_uint128_value get_coop_bal; new_coop = builtin add coop_bal coop_;
donations[coop] := new_coop;
Timestamp end
procedure IsSufficient(
value: Uint128,
amount: Uint128
)
is_sufficient = uint128_ge value amount; match is_sufficient with
| True => | False => e = { _exception : "donate.tyron-InsufficientBalance" }; throw e end end
transition Withdrawal( amount: Uint128 )
current_init <-& init.dApp;
get_wfp <-& current_init.dns[wfp]; wfp_addr = option_bystr20_value get_wfp;
is_wfp = builtin eq _sender wfp_addr; match is_wfp with
| True =>
get_balance <- donations[wfp]; balance = option_uint128_value get_balance;
IsSufficient balance amount;
msg = let m = { _tag: "AddFunds"; _recipient: wfp_addr; _amount: amount } in one_msg m; send msg;
new_bal = builtin sub balance amount; donations[wfp] := new_bal
| False =>
get_insurance <-& current_init.dns[insurance]; insurance_addr = option_bystr20_value get_insurance;
is_insurance = builtin eq _sender insurance_addr; match is_insurance with
| True =>
get_balance <- donations[insurance]; balance = option_uint128_value get_balance;
IsSufficient balance amount;
msg = let m = { _tag: "AddFunds"; _recipient: insurance_addr; _amount: amount } in one_msg m; send msg;
new_bal = builtin sub balance amount; donations[insurance] := new_bal
| False =>
get_coop <-& current_init.dns[coop]; coop_addr = option_bystr20_value get_coop;
is_coop = builtin eq _sender coop_addr; match is_coop with
| True =>
get_balance <- donations[coop]; balance = option_uint128_value get_balance;
IsSufficient balance amount;
msg = let m = { _tag: "AddFunds"; _recipient: coop_addr; _amount: amount } in one_msg m; send msg;
new_bal = builtin sub balance amount; donations[coop] := new_bal
| False => e = { _exception : "donate.tyron-WrongCaller" }; throw e end end end end
transition XPoints( amount: Uint128 )
current_init <-& init.dApp;
xPointsDApp = "xpoints"; get_addr <-& current_init.dns[xPointsDApp]; addr = option_bystr20_value get_addr;
is_xPoints = builtin eq _sender addr; match is_xPoints with
| True => | False => e = { _exception : "donate.tyron-WrongCaller" }; throw e end;
get_xPoints <- xpoints[_origin]; x_points = option_uint128_value get_xPoints; IsSufficient x_points amount;
new_bal = builtin sub x_points amount; xpoints[_origin] := new_bal end`