1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let boss = addressFromStringValue("3PRE5KH9oPGfFPs7fGnQcJ4wNshEDUPGj1t") |
---|
5 | 5 | | |
---|
6 | 6 | | let adminPublicKey = base58'Cr1ybL2JGg9GwJHA2JwqxBPfSW6Q7Jg4HvNrsEiCsHu6' |
---|
7 | 7 | | |
---|
8 | 8 | | func getPutGet (is_stable) = { |
---|
9 | 9 | | let putFunc = if ((is_stable == 1)) |
---|
10 | 10 | | then "putOneTknV2" |
---|
11 | 11 | | else "putOneTkn" |
---|
12 | 12 | | let getFunc = if ((is_stable == 1)) |
---|
13 | 13 | | then "getOneTknV2" |
---|
14 | 14 | | else "getOneTkn" |
---|
15 | 15 | | $Tuple2(putFunc, getFunc) |
---|
16 | 16 | | } |
---|
17 | 17 | | |
---|
18 | 18 | | |
---|
19 | 19 | | func getBalance (assetId) = match assetId { |
---|
20 | 20 | | case b: ByteVector => |
---|
21 | 21 | | assetBalance(this, b) |
---|
22 | 22 | | case _ => |
---|
23 | 23 | | wavesBalance(this).available |
---|
24 | 24 | | } |
---|
25 | 25 | | |
---|
26 | 26 | | |
---|
27 | 27 | | func getBase1 (data) = { |
---|
28 | 28 | | let p_data = split(data, "_") |
---|
29 | 29 | | let a = p_data[0] |
---|
30 | 30 | | let a2 = p_data[1] |
---|
31 | 31 | | let assetIn = p_data[2] |
---|
32 | 32 | | let amountIn = p_data[3] |
---|
33 | 33 | | $Tuple4(a, a2, assetIn, amountIn) |
---|
34 | 34 | | } |
---|
35 | 35 | | |
---|
36 | 36 | | |
---|
37 | 37 | | func getBase2 (data) = { |
---|
38 | 38 | | let p_data = split(data, "_") |
---|
39 | 39 | | let p1 = p_data[0] |
---|
40 | 40 | | let lp1 = p_data[1] |
---|
41 | 41 | | let is_stable_1 = p_data[2] |
---|
42 | 42 | | $Tuple3(p1, lp1, is_stable_1) |
---|
43 | 43 | | } |
---|
44 | 44 | | |
---|
45 | 45 | | |
---|
46 | 46 | | func getAssetBytes (assetId) = if ((assetId == "WAVES")) |
---|
47 | 47 | | then unit |
---|
48 | 48 | | else fromBase58String(assetId) |
---|
49 | 49 | | |
---|
50 | 50 | | |
---|
51 | 51 | | @Callable(i) |
---|
52 | 52 | | func setAmout (a) = if ((i.caller != this)) |
---|
53 | 53 | | then throw("you are not allowed to set!") |
---|
54 | 54 | | else [IntegerEntry("montant", a)] |
---|
55 | 55 | | |
---|
56 | 56 | | |
---|
57 | 57 | | |
---|
58 | 58 | | @Callable(i) |
---|
59 | 59 | | func setKeyValString (key,val) = if ((i.caller != this)) |
---|
60 | 60 | | then throw("you are not allowed to set!") |
---|
61 | 61 | | else [StringEntry(key, val)] |
---|
62 | 62 | | |
---|
63 | 63 | | |
---|
64 | 64 | | |
---|
65 | 65 | | @Callable(i) |
---|
66 | 66 | | func y (data) = if (if ((i.caller != this)) |
---|
67 | 67 | | then (i.caller != boss) |
---|
68 | 68 | | else false) |
---|
69 | 69 | | then throw("you are not allowed to arb!") |
---|
70 | 70 | | else { |
---|
71 | 71 | | let data_array = split_4C(data, "|") |
---|
72 | 72 | | let $t015861642 = getBase1(data_array[0]) |
---|
73 | 73 | | let a = $t015861642._1 |
---|
74 | 74 | | let a2 = $t015861642._2 |
---|
75 | 75 | | let assetIn = $t015861642._3 |
---|
76 | 76 | | let amountIn = $t015861642._4 |
---|
77 | 77 | | let $t016471699 = getBase2(data_array[1]) |
---|
78 | 78 | | let p1 = $t016471699._1 |
---|
79 | 79 | | let lp1 = $t016471699._2 |
---|
80 | 80 | | let is_stable_1 = $t016471699._3 |
---|
81 | 81 | | let $t017041756 = getBase2(data_array[2]) |
---|
82 | 82 | | let p2 = $t017041756._1 |
---|
83 | 83 | | let lp2 = $t017041756._2 |
---|
84 | 84 | | let is_stable_2 = $t017041756._3 |
---|
85 | 85 | | let $t017611813 = getBase2(data_array[3]) |
---|
86 | 86 | | let p3 = $t017611813._1 |
---|
87 | 87 | | let lp3 = $t017611813._2 |
---|
88 | 88 | | let is_stable_3 = $t017611813._3 |
---|
89 | 89 | | let $t018191885 = getPutGet(value(parseInt(is_stable_1))) |
---|
90 | 90 | | let putFunc1 = $t018191885._1 |
---|
91 | 91 | | let getFunc1 = $t018191885._2 |
---|
92 | 92 | | let $t018901956 = getPutGet(value(parseInt(is_stable_2))) |
---|
93 | 93 | | let putFunc2 = $t018901956._1 |
---|
94 | 94 | | let getFunc2 = $t018901956._2 |
---|
95 | 95 | | let $t019612027 = getPutGet(value(parseInt(is_stable_3))) |
---|
96 | 96 | | let putFunc3 = $t019612027._1 |
---|
97 | 97 | | let getFunc3 = $t019612027._2 |
---|
98 | 98 | | let amount_bef_assetIn = getBalance(getAssetBytes(assetIn)) |
---|
99 | 99 | | if ((amount_bef_assetIn == amount_bef_assetIn)) |
---|
100 | 100 | | then { |
---|
101 | 101 | | let new_amountIn = if ((value(parseInt(amountIn)) > amount_bef_assetIn)) |
---|
102 | 102 | | then amount_bef_assetIn |
---|
103 | 103 | | else value(parseInt(amountIn)) |
---|
104 | 104 | | let amount_bef_asset1 = getBalance(getAssetBytes(a)) |
---|
105 | 105 | | if ((amount_bef_asset1 == amount_bef_asset1)) |
---|
106 | 106 | | then { |
---|
107 | 107 | | let put1 = invoke(Address(fromBase58String(p1)), putFunc1, [1, false], [AttachedPayment(getAssetBytes(assetIn), new_amountIn)]) |
---|
108 | 108 | | if ((put1 == put1)) |
---|
109 | 109 | | then { |
---|
110 | 110 | | let lp1_assetid = fromBase58String(lp1) |
---|
111 | 111 | | let lpBalance_1 = getBalance(lp1_assetid) |
---|
112 | 112 | | if ((lpBalance_1 == lpBalance_1)) |
---|
113 | 113 | | then { |
---|
114 | 114 | | let get1 = invoke(Address(fromBase58String(p1)), getFunc1, [a, 1], [AttachedPayment(lp1_assetid, lpBalance_1)]) |
---|
115 | 115 | | if ((get1 == get1)) |
---|
116 | 116 | | then { |
---|
117 | 117 | | let nb = (getBalance(getAssetBytes(a)) - amount_bef_asset1) |
---|
118 | 118 | | if ((nb == nb)) |
---|
119 | 119 | | then { |
---|
120 | 120 | | let amount_bef_asset2 = getBalance(getAssetBytes(a2)) |
---|
121 | 121 | | if ((amount_bef_asset2 == amount_bef_asset2)) |
---|
122 | 122 | | then { |
---|
123 | 123 | | let put2 = invoke(Address(fromBase58String(p2)), putFunc2, [1, false], [AttachedPayment(getAssetBytes(a), nb)]) |
---|
124 | 124 | | if ((put2 == put2)) |
---|
125 | 125 | | then { |
---|
126 | 126 | | let lp2_assetid = fromBase58String(lp2) |
---|
127 | 127 | | let lpBalance_2 = getBalance(lp2_assetid) |
---|
128 | 128 | | if ((lpBalance_2 == lpBalance_2)) |
---|
129 | 129 | | then { |
---|
130 | 130 | | let get2 = invoke(Address(fromBase58String(p2)), getFunc2, [a2, 1], [AttachedPayment(lp2_assetid, lpBalance_2)]) |
---|
131 | 131 | | if ((get2 == get2)) |
---|
132 | 132 | | then { |
---|
133 | 133 | | let nb2 = (getBalance(getAssetBytes(a2)) - amount_bef_asset2) |
---|
134 | 134 | | if ((nb2 == nb2)) |
---|
135 | 135 | | then { |
---|
136 | 136 | | let amount_bef_base_asset = getBalance(getAssetBytes(assetIn)) |
---|
137 | 137 | | if ((amount_bef_base_asset == amount_bef_base_asset)) |
---|
138 | 138 | | then { |
---|
139 | 139 | | let put3 = invoke(Address(fromBase58String(p3)), putFunc3, [1, false], [AttachedPayment(getAssetBytes(a2), nb2)]) |
---|
140 | 140 | | if ((put3 == put3)) |
---|
141 | 141 | | then { |
---|
142 | 142 | | let lp3_assetid = fromBase58String(lp3) |
---|
143 | 143 | | let lpBalance_3 = getBalance(lp3_assetid) |
---|
144 | 144 | | if ((lpBalance_3 == lpBalance_3)) |
---|
145 | 145 | | then { |
---|
146 | 146 | | let get3 = invoke(Address(fromBase58String(p3)), getFunc3, [assetIn, 1], [AttachedPayment(lp3_assetid, lpBalance_3)]) |
---|
147 | 147 | | if ((get3 == get3)) |
---|
148 | 148 | | then { |
---|
149 | 149 | | let nb3 = (getBalance(getAssetBytes(assetIn)) - amount_bef_base_asset) |
---|
150 | 150 | | if ((nb3 == nb3)) |
---|
151 | 151 | | then if ((nb3 > (new_amountIn + 100))) |
---|
152 | 152 | | then [ScriptTransfer(i.caller, nb3, getAssetBytes(assetIn))] |
---|
153 | 153 | | else throw(((((((("new_amountIn = " + amountIn) + ", newBal_1: ") + toString(nb)) + ", newBal_2: ") + toString(nb2)) + ", newBal_3: ") + toString(nb3))) |
---|
154 | 154 | | else throw("Strict value is not equal to itself.") |
---|
155 | 155 | | } |
---|
156 | 156 | | else throw("Strict value is not equal to itself.") |
---|
157 | 157 | | } |
---|
158 | 158 | | else throw("Strict value is not equal to itself.") |
---|
159 | 159 | | } |
---|
160 | 160 | | else throw("Strict value is not equal to itself.") |
---|
161 | 161 | | } |
---|
162 | 162 | | else throw("Strict value is not equal to itself.") |
---|
163 | 163 | | } |
---|
164 | 164 | | else throw("Strict value is not equal to itself.") |
---|
165 | 165 | | } |
---|
166 | 166 | | else throw("Strict value is not equal to itself.") |
---|
167 | 167 | | } |
---|
168 | 168 | | else throw("Strict value is not equal to itself.") |
---|
169 | 169 | | } |
---|
170 | 170 | | else throw("Strict value is not equal to itself.") |
---|
171 | 171 | | } |
---|
172 | 172 | | else throw("Strict value is not equal to itself.") |
---|
173 | 173 | | } |
---|
174 | 174 | | else throw("Strict value is not equal to itself.") |
---|
175 | 175 | | } |
---|
176 | 176 | | else throw("Strict value is not equal to itself.") |
---|
177 | 177 | | } |
---|
178 | 178 | | else throw("Strict value is not equal to itself.") |
---|
179 | 179 | | } |
---|
180 | 180 | | else throw("Strict value is not equal to itself.") |
---|
181 | 181 | | } |
---|
182 | 182 | | else throw("Strict value is not equal to itself.") |
---|
183 | 183 | | } |
---|
184 | 184 | | else throw("Strict value is not equal to itself.") |
---|
185 | 185 | | } |
---|
186 | 186 | | |
---|
187 | 187 | | |
---|
188 | 188 | | @Verifier(tx) |
---|
189 | 189 | | func verify () = if (sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) |
---|
190 | 190 | | then true |
---|
191 | 191 | | else sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], adminPublicKey) |
---|
192 | 192 | | |
---|