tx · 3KojrtqfHoJe5euPC8h4gvhNLqnDSfti6yXYZXrxvWeJ 3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv: -0.01000000 Waves 2023.10.07 02:28 [2787436] smart account 3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv > SELF 0.00000000 Waves
{ "type": 13, "id": "3KojrtqfHoJe5euPC8h4gvhNLqnDSfti6yXYZXrxvWeJ", "fee": 1000000, "feeAssetId": null, "timestamp": 1696634960027, "version": 2, "chainId": 84, "sender": "3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv", "senderPublicKey": "EnUXxxhBK8wUfh1FveDYv9G5HBMXop6YwZWzVrBrLo2i", "proofs": [ "7zE4eyVjCY6D6vZQL4jFxyEPnfnvZFMSzVxCpLLic1k8oHWRXDeT8WMqqnBWLy9VFkpXdVdtp66B3WHhUs5VjBw" ], "script": "base64:BgIJCAISBQoDAQEYAwELd3JpdGVTdHJpbmcCA2tleQtzdHJpbmdWYWx1ZQkBC1N0cmluZ0VudHJ5AgUDa2V5BQtzdHJpbmdWYWx1ZQENc3BsaXRDZm1tSnNvbgEFZW50cnkJALUJAgUFZW50cnkCAS8BFGRpc3RyaWJ1dGVEaWZmZXJlbmNlAgVzd2FwcwRkaWZmBAp0b3RhbFN3YXBzCQCQAwEFBXN3YXBzCgENYWRqdXN0QW1vdW50cwIFYWNjdW0EbmV4dAQJJHQwNTk2NjM4BQVhY2N1bQQNYWRqdXN0ZWRTd2FwcwgFCSR0MDU5NjYzOAJfMQQNcmVtYWluaW5nRGlmZggFCSR0MDU5NjYzOAJfMgQEaXRlbQkBDXNwbGl0Q2ZtbUpzb24BBQRuZXh0BAtpbnB1dEFtb3VudAkAtgkBCQCRAwIFBGl0ZW0AAgQHJG1hdGNoMAULaW5wdXRBbW91bnQDCQABAgUHJG1hdGNoMAIDSW50BAVpbnB1dAUHJG1hdGNoMAQOYW1vdW50VG9BZGp1c3QECnJlbWFpbkRpZmYJAGkCBQ1yZW1haW5pbmd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9vgfFQUfAXJNYCijME Next: Ca66mpEXSrbvRDtuvEMVGJ2SQ3GRfcrBy7rJXboDTjtS Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let adminAddress = valueOrElse(getString(this, "admin"), "") | |
5 | - | ||
6 | - | let wxSwapAddress = "3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93" | |
7 | - | ||
8 | 4 | func writeString (key,stringValue) = StringEntry(key, stringValue) | |
9 | - | ||
10 | - | ||
11 | - | func writeInteger (key,integerValue) = IntegerEntry(key, integerValue) | |
12 | - | ||
13 | - | ||
14 | - | func isAdmin (callerAddress) = if ((callerAddress == fromBase58String(adminAddress))) | |
15 | - | then true | |
16 | - | else false | |
17 | 5 | ||
18 | 6 | ||
19 | 7 | func splitCfmmJson (entry) = split(entry, "/") | |
20 | 8 | ||
21 | 9 | ||
22 | - | func determinePlatform (cfmm,tokenIdIn,tokenIdOut) = { | |
23 | - | let item = splitCfmmJson(cfmm) | |
24 | - | let inputAmount = parseInt(item[2]) | |
25 | - | match inputAmount { | |
26 | - | case inputAmount: Int => | |
27 | - | if ((item[0] == "SWOP")) | |
28 | - | then invoke(addressFromStringValue(item[1]), "exchange", [1], [AttachedPayment(fromBase58String(tokenIdIn), inputAmount)]) | |
29 | - | else if ((item[0] == "Waves Exchange")) | |
30 | - | then invoke(addressFromStringValue(wxSwapAddress), "swap", [1, tokenIdOut, adminAddress], [AttachedPayment(fromBase58String(tokenIdIn), inputAmount)]) | |
31 | - | else if ((item[0] == "Puzzle Swap")) | |
32 | - | then invoke(addressFromStringValue(item[1]), "swap", [tokenIdOut, 1], [AttachedPayment(fromBase58String(tokenIdIn), inputAmount)]) | |
33 | - | else throw("Platform id does not match!") | |
34 | - | case _ => | |
35 | - | throw("value is not an int!") | |
36 | - | } | |
37 | - | } | |
38 | - | ||
39 | - | ||
40 | - | func processCfmms (swaps,tokenIdIn,tokenIdOut) = { | |
41 | - | func invokeSwap (accum,next) = { | |
42 | - | let $t022642291 = accum | |
43 | - | let result = $t022642291._1 | |
44 | - | let index = $t022642291._2 | |
45 | - | if ((size(swaps) > index)) | |
46 | - | then $Tuple2(determinePlatform(next, tokenIdIn, tokenIdOut), (index + 1)) | |
47 | - | else $Tuple2(result, index) | |
48 | - | } | |
49 | - | ||
50 | - | let $l = swaps | |
51 | - | let $s = size($l) | |
52 | - | let $acc0 = $Tuple2(nil, 0) | |
53 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
54 | - | then $a | |
55 | - | else invokeSwap($a, $l[$i]) | |
56 | - | ||
57 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
58 | - | then $a | |
59 | - | else throw("List size exceeds 40") | |
60 | - | ||
61 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 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) | |
62 | - | } | |
63 | - | ||
64 | - | ||
65 | 10 | func distributeDifference (swaps,diff) = { | |
66 | 11 | let totalSwaps = size(swaps) | |
67 | 12 | func adjustAmounts (accum,next) = { | |
68 | - | let $ | |
69 | - | let adjustedSwaps = $ | |
70 | - | let remainingDiff = $ | |
13 | + | let $t0596638 = accum | |
14 | + | let adjustedSwaps = $t0596638._1 | |
15 | + | let remainingDiff = $t0596638._2 | |
71 | 16 | let item = splitCfmmJson(next) | |
72 | 17 | let inputAmount = parseInt(item[2]) | |
73 | 18 | match inputAmount { | |
108 | 53 | } | |
109 | 54 | ||
110 | 55 | ||
111 | - | func handleSecondInputAmount (predeterminedAmount,availableAmount,swaps) = { | |
56 | + | @Callable(i) | |
57 | + | func call (predeterminedAmount,availableAmount,swaps) = { | |
112 | 58 | let diff = (availableAmount - predeterminedAmount) | |
113 | 59 | let adjustedSwaps = if ((diff != 0)) | |
114 | 60 | then distributeDifference(swaps, diff)._1 | |
115 | 61 | else swaps | |
116 | - | ||
62 | + | [writeString("swaps", makeString(swaps, ",")), writeString("adjustedSwaps", makeString(adjustedSwaps, ","))] | |
117 | 63 | } | |
118 | - | ||
119 | - | ||
120 | - | @Callable(i) | |
121 | - | func setup () = if (!(isDefined(getString(this, "admin")))) | |
122 | - | then [writeString("admin", toBase58String(i.caller.bytes))] | |
123 | - | else throw("Dapp already setup!") | |
124 | - | ||
125 | - | ||
126 | - | ||
127 | - | @Callable(i) | |
128 | - | func basicArb (startAmount,secondAmountIn,firstToken,secondToken,firstSwap,secondSwap) = if (isAdmin(i.caller.bytes)) | |
129 | - | then { | |
130 | - | let firstTokenId = { | |
131 | - | let tId = fromBase58String(firstToken) | |
132 | - | match tId { | |
133 | - | case tId: ByteVector => | |
134 | - | tId | |
135 | - | case _ => | |
136 | - | throw("Invalid datatype") | |
137 | - | } | |
138 | - | } | |
139 | - | let availableAmountFirstToken = assetBalance(this, firstTokenId) | |
140 | - | if ((availableAmountFirstToken >= startAmount)) | |
141 | - | then { | |
142 | - | let result = processCfmms(firstSwap, firstToken, secondToken) | |
143 | - | let secondTokenId = { | |
144 | - | let id = fromBase58String(secondToken) | |
145 | - | match id { | |
146 | - | case id: ByteVector => | |
147 | - | id | |
148 | - | case _ => | |
149 | - | throw("Invalid datatype") | |
150 | - | } | |
151 | - | } | |
152 | - | let availableAmountSecondToken = assetBalance(this, secondTokenId) | |
153 | - | let secondSwaps = if ((availableAmountSecondToken == secondAmountIn)) | |
154 | - | then secondSwap | |
155 | - | else handleSecondInputAmount(secondAmountIn, availableAmountSecondToken, secondSwap) | |
156 | - | let resultTwo = processCfmms(secondSwaps, secondToken, firstToken) | |
157 | - | let currentStartTokenBalance = assetBalance(this, firstTokenId) | |
158 | - | if ((currentStartTokenBalance > startAmount)) | |
159 | - | then nil | |
160 | - | else throw("Trade was not profitable!") | |
161 | - | } | |
162 | - | else throw("Available input amount is not sufficient!") | |
163 | - | } | |
164 | - | else throw("Address does not match with admin address!") | |
165 | - | ||
166 | - | ||
167 | - | ||
168 | - | @Callable(i) | |
169 | - | func updateStringEntry (key,stringValue) = if (isAdmin(i.caller.bytes)) | |
170 | - | then [writeString(key, stringValue)] | |
171 | - | else throw("Address does not match with admin address!") | |
172 | - | ||
173 | - | ||
174 | - | ||
175 | - | @Callable(i) | |
176 | - | func updateIntegerEntry (key,integerValue) = if (isAdmin(i.caller.bytes)) | |
177 | - | then [writeInteger(key, integerValue)] | |
178 | - | else throw("Address does not match with admin address!") | |
179 | - | ||
180 | - | ||
181 | - | ||
182 | - | @Callable(i) | |
183 | - | func deleteStorageEntry (key) = if (isAdmin(i.caller.bytes)) | |
184 | - | then [DeleteEntry(key)] | |
185 | - | else throw("Address does not match with admin address!") | |
186 | 64 | ||
187 | 65 | ||
188 | 66 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let adminAddress = valueOrElse(getString(this, "admin"), "") | |
5 | - | ||
6 | - | let wxSwapAddress = "3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93" | |
7 | - | ||
8 | 4 | func writeString (key,stringValue) = StringEntry(key, stringValue) | |
9 | - | ||
10 | - | ||
11 | - | func writeInteger (key,integerValue) = IntegerEntry(key, integerValue) | |
12 | - | ||
13 | - | ||
14 | - | func isAdmin (callerAddress) = if ((callerAddress == fromBase58String(adminAddress))) | |
15 | - | then true | |
16 | - | else false | |
17 | 5 | ||
18 | 6 | ||
19 | 7 | func splitCfmmJson (entry) = split(entry, "/") | |
20 | 8 | ||
21 | 9 | ||
22 | - | func determinePlatform (cfmm,tokenIdIn,tokenIdOut) = { | |
23 | - | let item = splitCfmmJson(cfmm) | |
24 | - | let inputAmount = parseInt(item[2]) | |
25 | - | match inputAmount { | |
26 | - | case inputAmount: Int => | |
27 | - | if ((item[0] == "SWOP")) | |
28 | - | then invoke(addressFromStringValue(item[1]), "exchange", [1], [AttachedPayment(fromBase58String(tokenIdIn), inputAmount)]) | |
29 | - | else if ((item[0] == "Waves Exchange")) | |
30 | - | then invoke(addressFromStringValue(wxSwapAddress), "swap", [1, tokenIdOut, adminAddress], [AttachedPayment(fromBase58String(tokenIdIn), inputAmount)]) | |
31 | - | else if ((item[0] == "Puzzle Swap")) | |
32 | - | then invoke(addressFromStringValue(item[1]), "swap", [tokenIdOut, 1], [AttachedPayment(fromBase58String(tokenIdIn), inputAmount)]) | |
33 | - | else throw("Platform id does not match!") | |
34 | - | case _ => | |
35 | - | throw("value is not an int!") | |
36 | - | } | |
37 | - | } | |
38 | - | ||
39 | - | ||
40 | - | func processCfmms (swaps,tokenIdIn,tokenIdOut) = { | |
41 | - | func invokeSwap (accum,next) = { | |
42 | - | let $t022642291 = accum | |
43 | - | let result = $t022642291._1 | |
44 | - | let index = $t022642291._2 | |
45 | - | if ((size(swaps) > index)) | |
46 | - | then $Tuple2(determinePlatform(next, tokenIdIn, tokenIdOut), (index + 1)) | |
47 | - | else $Tuple2(result, index) | |
48 | - | } | |
49 | - | ||
50 | - | let $l = swaps | |
51 | - | let $s = size($l) | |
52 | - | let $acc0 = $Tuple2(nil, 0) | |
53 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
54 | - | then $a | |
55 | - | else invokeSwap($a, $l[$i]) | |
56 | - | ||
57 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
58 | - | then $a | |
59 | - | else throw("List size exceeds 40") | |
60 | - | ||
61 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 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) | |
62 | - | } | |
63 | - | ||
64 | - | ||
65 | 10 | func distributeDifference (swaps,diff) = { | |
66 | 11 | let totalSwaps = size(swaps) | |
67 | 12 | func adjustAmounts (accum,next) = { | |
68 | - | let $ | |
69 | - | let adjustedSwaps = $ | |
70 | - | let remainingDiff = $ | |
13 | + | let $t0596638 = accum | |
14 | + | let adjustedSwaps = $t0596638._1 | |
15 | + | let remainingDiff = $t0596638._2 | |
71 | 16 | let item = splitCfmmJson(next) | |
72 | 17 | let inputAmount = parseInt(item[2]) | |
73 | 18 | match inputAmount { | |
74 | 19 | case input: Int => | |
75 | 20 | let amountToAdjust = { | |
76 | 21 | let remainDiff = (remainingDiff / ((totalSwaps - size(adjustedSwaps)) + 1)) | |
77 | 22 | match remainDiff { | |
78 | 23 | case x: Int => | |
79 | 24 | if ((remainingDiff > 0)) | |
80 | 25 | then min([input, x]) | |
81 | 26 | else if ((0 > remainingDiff)) | |
82 | 27 | then max([(-(input) + 1), x]) | |
83 | 28 | else 0 | |
84 | 29 | case _ => | |
85 | 30 | throw("Wrong datatype") | |
86 | 31 | } | |
87 | 32 | } | |
88 | 33 | let newInputAmount = max([1, (input + amountToAdjust)]) | |
89 | 34 | let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(newInputAmount)) | |
90 | 35 | $Tuple2((adjustedSwaps :+ newItem), (remainingDiff - (amountToAdjust * ((totalSwaps - size(adjustedSwaps)) + 1)))) | |
91 | 36 | case _ => | |
92 | 37 | throw("Input has wrong datatype!") | |
93 | 38 | } | |
94 | 39 | } | |
95 | 40 | ||
96 | 41 | let $l = swaps | |
97 | 42 | let $s = size($l) | |
98 | 43 | let $acc0 = $Tuple2(nil, diff) | |
99 | 44 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
100 | 45 | then $a | |
101 | 46 | else adjustAmounts($a, $l[$i]) | |
102 | 47 | ||
103 | 48 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
104 | 49 | then $a | |
105 | 50 | else throw("List size exceeds 40") | |
106 | 51 | ||
107 | 52 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 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) | |
108 | 53 | } | |
109 | 54 | ||
110 | 55 | ||
111 | - | func handleSecondInputAmount (predeterminedAmount,availableAmount,swaps) = { | |
56 | + | @Callable(i) | |
57 | + | func call (predeterminedAmount,availableAmount,swaps) = { | |
112 | 58 | let diff = (availableAmount - predeterminedAmount) | |
113 | 59 | let adjustedSwaps = if ((diff != 0)) | |
114 | 60 | then distributeDifference(swaps, diff)._1 | |
115 | 61 | else swaps | |
116 | - | ||
62 | + | [writeString("swaps", makeString(swaps, ",")), writeString("adjustedSwaps", makeString(adjustedSwaps, ","))] | |
117 | 63 | } | |
118 | - | ||
119 | - | ||
120 | - | @Callable(i) | |
121 | - | func setup () = if (!(isDefined(getString(this, "admin")))) | |
122 | - | then [writeString("admin", toBase58String(i.caller.bytes))] | |
123 | - | else throw("Dapp already setup!") | |
124 | - | ||
125 | - | ||
126 | - | ||
127 | - | @Callable(i) | |
128 | - | func basicArb (startAmount,secondAmountIn,firstToken,secondToken,firstSwap,secondSwap) = if (isAdmin(i.caller.bytes)) | |
129 | - | then { | |
130 | - | let firstTokenId = { | |
131 | - | let tId = fromBase58String(firstToken) | |
132 | - | match tId { | |
133 | - | case tId: ByteVector => | |
134 | - | tId | |
135 | - | case _ => | |
136 | - | throw("Invalid datatype") | |
137 | - | } | |
138 | - | } | |
139 | - | let availableAmountFirstToken = assetBalance(this, firstTokenId) | |
140 | - | if ((availableAmountFirstToken >= startAmount)) | |
141 | - | then { | |
142 | - | let result = processCfmms(firstSwap, firstToken, secondToken) | |
143 | - | let secondTokenId = { | |
144 | - | let id = fromBase58String(secondToken) | |
145 | - | match id { | |
146 | - | case id: ByteVector => | |
147 | - | id | |
148 | - | case _ => | |
149 | - | throw("Invalid datatype") | |
150 | - | } | |
151 | - | } | |
152 | - | let availableAmountSecondToken = assetBalance(this, secondTokenId) | |
153 | - | let secondSwaps = if ((availableAmountSecondToken == secondAmountIn)) | |
154 | - | then secondSwap | |
155 | - | else handleSecondInputAmount(secondAmountIn, availableAmountSecondToken, secondSwap) | |
156 | - | let resultTwo = processCfmms(secondSwaps, secondToken, firstToken) | |
157 | - | let currentStartTokenBalance = assetBalance(this, firstTokenId) | |
158 | - | if ((currentStartTokenBalance > startAmount)) | |
159 | - | then nil | |
160 | - | else throw("Trade was not profitable!") | |
161 | - | } | |
162 | - | else throw("Available input amount is not sufficient!") | |
163 | - | } | |
164 | - | else throw("Address does not match with admin address!") | |
165 | - | ||
166 | - | ||
167 | - | ||
168 | - | @Callable(i) | |
169 | - | func updateStringEntry (key,stringValue) = if (isAdmin(i.caller.bytes)) | |
170 | - | then [writeString(key, stringValue)] | |
171 | - | else throw("Address does not match with admin address!") | |
172 | - | ||
173 | - | ||
174 | - | ||
175 | - | @Callable(i) | |
176 | - | func updateIntegerEntry (key,integerValue) = if (isAdmin(i.caller.bytes)) | |
177 | - | then [writeInteger(key, integerValue)] | |
178 | - | else throw("Address does not match with admin address!") | |
179 | - | ||
180 | - | ||
181 | - | ||
182 | - | @Callable(i) | |
183 | - | func deleteStorageEntry (key) = if (isAdmin(i.caller.bytes)) | |
184 | - | then [DeleteEntry(key)] | |
185 | - | else throw("Address does not match with admin address!") | |
186 | 64 | ||
187 | 65 | ||
188 | 66 | @Verifier(tx) | |
189 | 67 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
190 | 68 |
github/deemru/w8io/169f3d6 44.76 ms ◑