1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let free_to_borrom = addressFromStringValue("3PG7CHvBatHpChwm8reH74wfEwk1PHc8Rqy") |
---|
5 | 5 | | |
---|
6 | 6 | | let USDN_ASSET_ID = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p' |
---|
7 | 7 | | |
---|
8 | 8 | | let boss = addressFromStringValue("3PRE5KH9oPGfFPs7fGnQcJ4wNshEDUPGj1t") |
---|
9 | 9 | | |
---|
10 | 10 | | let adminPublicKey = base58'Cr1ybL2JGg9GwJHA2JwqxBPfSW6Q7Jg4HvNrsEiCsHu6' |
---|
11 | 11 | | |
---|
12 | 12 | | let WX_SWAP_DAPP = Address(base58'3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93') |
---|
13 | 13 | | |
---|
14 | 14 | | let assets_in = ["DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"] |
---|
15 | 15 | | |
---|
16 | 16 | | func getBalance (assetId) = match assetId { |
---|
17 | 17 | | case b: ByteVector => |
---|
18 | 18 | | assetBalance(this, b) |
---|
19 | 19 | | case _ => |
---|
20 | 20 | | wavesBalance(this).available |
---|
21 | 21 | | } |
---|
22 | 22 | | |
---|
23 | 23 | | |
---|
24 | 24 | | func getBase1 (data) = { |
---|
25 | 25 | | let p_data = split_4C(data, "_") |
---|
26 | 26 | | let a = p_data[0] |
---|
27 | 27 | | let a2 = p_data[1] |
---|
28 | 28 | | let assetIn = assets_in[value(parseInt(p_data[2]))] |
---|
29 | 29 | | let amountIn = p_data[3] |
---|
30 | 30 | | $Tuple4(a, a2, assetIn, amountIn) |
---|
31 | 31 | | } |
---|
32 | 32 | | |
---|
33 | 33 | | |
---|
34 | 34 | | func getBase2 (data) = { |
---|
35 | 35 | | let p_data = split(data, "_") |
---|
36 | 36 | | let p1 = p_data[0] |
---|
37 | 37 | | let t = p_data[1] |
---|
38 | 38 | | $Tuple2(p1, t) |
---|
39 | 39 | | } |
---|
40 | 40 | | |
---|
41 | 41 | | |
---|
42 | 42 | | func getAssetBytes (assetId) = if ((assetId == "WAVES")) |
---|
43 | 43 | | then unit |
---|
44 | 44 | | else fromBase58String(assetId) |
---|
45 | 45 | | |
---|
46 | 46 | | |
---|
47 | 47 | | func swap_wx (p,asset,amount,a) = { |
---|
48 | 48 | | let call = invoke(WX_SWAP_DAPP, "swap", [1, a, toString(this)], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
49 | 49 | | if ((call == call)) |
---|
50 | 50 | | then nil |
---|
51 | 51 | | else throw("Strict value is not equal to itself.") |
---|
52 | 52 | | } |
---|
53 | 53 | | |
---|
54 | 54 | | |
---|
55 | 55 | | func swap_swop (p,asset,amount) = { |
---|
56 | 56 | | let swap = invoke(Address(fromBase58String(p)), "exchange", [1], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
57 | 57 | | if ((swap == swap)) |
---|
58 | 58 | | then nil |
---|
59 | 59 | | else throw("Strict value is not equal to itself.") |
---|
60 | 60 | | } |
---|
61 | 61 | | |
---|
62 | 62 | | |
---|
63 | 63 | | func swap_puzzle (p,asset,amount,assetOut) = { |
---|
64 | 64 | | let swap = invoke(Address(fromBase58String(p)), "swap", [assetOut, 1], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
65 | 65 | | if ((swap == swap)) |
---|
66 | 66 | | then nil |
---|
67 | 67 | | else throw("Strict value is not equal to itself.") |
---|
68 | 68 | | } |
---|
69 | 69 | | |
---|
70 | 70 | | |
---|
71 | 71 | | @Callable(i) |
---|
72 | 72 | | func borrow (amnt) = if (!(containsElement([free_to_borrom, boss, this], i.caller))) |
---|
73 | 73 | | then throw("you are not allowed to borrow!") |
---|
74 | 74 | | else { |
---|
75 | 75 | | let currentBal = getBalance(USDN_ASSET_ID) |
---|
76 | 76 | | if ((amnt > currentBal)) |
---|
77 | 77 | | then throw("You cannnot borrow that much") |
---|
78 | 78 | | else [ScriptTransfer(i.caller, amnt, USDN_ASSET_ID)] |
---|
79 | 79 | | } |
---|
80 | 80 | | |
---|
81 | 81 | | |
---|
82 | 82 | | |
---|
83 | 83 | | @Callable(i) |
---|
84 | 84 | | func setTreshold (amnt) = if (!(containsElement([free_to_borrom, boss, this], i.caller))) |
---|
85 | 85 | | then throw("you are not allowed to do that!") |
---|
86 | 86 | | else [IntegerEntry("treshold", amnt)] |
---|
87 | 87 | | |
---|
88 | 88 | | |
---|
89 | 89 | | |
---|
90 | 90 | | @Callable(i) |
---|
91 | 91 | | func y (data) = if (if ((i.caller != this)) |
---|
92 | 92 | | then (i.caller != boss) |
---|
93 | 93 | | else false) |
---|
94 | 94 | | then throw("you are not allowed to arb!") |
---|
95 | 95 | | else { |
---|
96 | 96 | | let data_array = split_4C(data, "|") |
---|
97 | 97 | | let $t027512807 = getBase1(data_array[0]) |
---|
98 | 98 | | let a = $t027512807._1 |
---|
99 | 99 | | let a2 = $t027512807._2 |
---|
100 | 100 | | let assetIn = $t027512807._3 |
---|
101 | 101 | | let amountIn = $t027512807._4 |
---|
102 | 102 | | let $t028122850 = getBase2(data_array[1]) |
---|
103 | 103 | | let p1 = $t028122850._1 |
---|
104 | 104 | | let t1 = $t028122850._2 |
---|
105 | 105 | | let $t028552893 = getBase2(data_array[2]) |
---|
106 | 106 | | let p2 = $t028552893._1 |
---|
107 | 107 | | let t2 = $t028552893._2 |
---|
108 | 108 | | let $t028982936 = getBase2(data_array[3]) |
---|
109 | 109 | | let p3 = $t028982936._1 |
---|
110 | 110 | | let t3 = $t028982936._2 |
---|
111 | 111 | | let idu = if ((size(data_array[4]) > 1)) |
---|
113 | 113 | | else nil |
---|
114 | 114 | | if (if ((size(idu) > 0)) |
---|
115 | 115 | | then true |
---|
116 | 116 | | else (1 >= size(data_array[4]))) |
---|
117 | 117 | | then { |
---|
118 | 118 | | let amount_bef_assetIn = getBalance(getAssetBytes(assetIn)) |
---|
119 | 119 | | if ((amount_bef_assetIn == amount_bef_assetIn)) |
---|
120 | 120 | | then { |
---|
121 | 121 | | let new_amountIn = if ((value(parseInt(amountIn)) > amount_bef_assetIn)) |
---|
122 | 122 | | then amount_bef_assetIn |
---|
123 | 123 | | else value(parseInt(amountIn)) |
---|
124 | 124 | | if ((new_amountIn == new_amountIn)) |
---|
125 | 125 | | then { |
---|
126 | 126 | | let amount_bef_asset1 = getBalance(getAssetBytes(a)) |
---|
127 | 127 | | if ((amount_bef_asset1 == amount_bef_asset1)) |
---|
128 | 128 | | then { |
---|
129 | 129 | | let swap1 = if ((t1 == "W")) |
---|
130 | 130 | | then swap_wx(p1, assetIn, new_amountIn, a) |
---|
131 | 131 | | else if ((t1 == "S")) |
---|
132 | 132 | | then swap_swop(p1, assetIn, new_amountIn) |
---|
133 | 133 | | else swap_puzzle(p1, assetIn, new_amountIn, a) |
---|
134 | 134 | | if ((swap1 == swap1)) |
---|
135 | 135 | | then { |
---|
136 | 136 | | let nb = (getBalance(getAssetBytes(a)) - amount_bef_asset1) |
---|
137 | 137 | | if ((nb == nb)) |
---|
138 | 138 | | then { |
---|
139 | 139 | | let amount_bef_asset2 = getBalance(getAssetBytes(a2)) |
---|
140 | 140 | | if ((amount_bef_asset2 == amount_bef_asset2)) |
---|
141 | 141 | | then { |
---|
142 | 142 | | let swap2 = if ((t2 == "W")) |
---|
143 | 143 | | then swap_wx(p2, a, nb, a2) |
---|
144 | 144 | | else if ((t2 == "S")) |
---|
145 | 145 | | then swap_swop(p2, a, nb) |
---|
146 | 146 | | else swap_puzzle(p2, a, nb, a2) |
---|
147 | 147 | | if ((swap2 == swap2)) |
---|
148 | 148 | | then { |
---|
149 | 149 | | let nb2 = (getBalance(getAssetBytes(a2)) - amount_bef_asset2) |
---|
150 | 150 | | if ((nb2 == nb2)) |
---|
151 | 151 | | then { |
---|
152 | 152 | | let amount_bef_base_asset = getBalance(getAssetBytes(assetIn)) |
---|
153 | 153 | | if ((amount_bef_base_asset == amount_bef_base_asset)) |
---|
154 | 154 | | then { |
---|
155 | 155 | | let swap3 = if ((t3 == "W")) |
---|
156 | 156 | | then swap_wx(p3, a2, nb2, assetIn) |
---|
157 | 157 | | else if ((t3 == "S")) |
---|
158 | 158 | | then swap_swop(p3, a2, nb2) |
---|
159 | 159 | | else swap_puzzle(p3, a2, nb2, assetIn) |
---|
160 | 160 | | if ((swap3 == swap3)) |
---|
161 | 161 | | then { |
---|
162 | 162 | | let nb3 = (getBalance(getAssetBytes(assetIn)) - amount_bef_base_asset) |
---|
163 | 163 | | if ((nb3 == nb3)) |
---|
164 | 164 | | then { |
---|
165 | 165 | | let treshold = valueOrElse(getInteger(this, "treshold"), 150000) |
---|
166 | 166 | | if ((nb3 > (new_amountIn + treshold))) |
---|
167 | 167 | | then [ScriptTransfer(i.caller, (nb3 - new_amountIn), getAssetBytes(assetIn))] |
---|
168 | 168 | | else throw(((((((((("origin amountIn = " + amountIn) + ", new_amountIn = ") + toString(new_amountIn)) + ", newBal_1: ") + toString(nb)) + ", newBal_2: ") + toString(nb2)) + ", newBal_3: ") + toString(nb3))) |
---|
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 | | else throw("Strict value is not equal to itself.") |
---|
187 | 187 | | } |
---|
188 | 188 | | else throw("Strict value is not equal to itself.") |
---|
189 | 189 | | } |
---|
190 | 190 | | else throw("Strict value is not equal to itself.") |
---|
191 | 191 | | } |
---|
192 | 192 | | else nil |
---|
193 | 193 | | } |
---|
194 | 194 | | |
---|
195 | 195 | | |
---|
196 | 196 | | @Verifier(tx) |
---|
197 | 197 | | func verify () = if (sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) |
---|
198 | 198 | | then true |
---|
199 | 199 | | else sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], adminPublicKey) |
---|
200 | 200 | | |
---|