tx · mXUacmQ3Fgh34SaZy7GCHkgvRPy6VysbnSm5VUnRpsc 3N9Tq8RmGw456c1eYphzoMyvtwJGrY98jfr: -0.01400000 Waves 2022.04.07 15:42 [1998151] smart account 3N9Tq8RmGw456c1eYphzoMyvtwJGrY98jfr > SELF 0.00000000 Waves
{ "type": 13, "id": "mXUacmQ3Fgh34SaZy7GCHkgvRPy6VysbnSm5VUnRpsc", "fee": 1400000, "feeAssetId": null, "timestamp": 1649335369381, "version": 2, "chainId": 84, "sender": "3N9Tq8RmGw456c1eYphzoMyvtwJGrY98jfr", "senderPublicKey": "He9ZSnjQZGhUkdUsMVVz4t6eAU1c2owedXGCfY1WZvnU", "proofs": [ "xt9tLC4yPzaQXybM1QziD6iMybAbrYgLcuPq6zYch1YtECQfKzbUBvxT7fwfAtdM9cnu71hLa4VYjnH8GQRYtV8" ], "script": "base64:AAIFAAAAAAAAAB8IAhIFCgMIAQQSAwoBCBIDCgEIEgQKAggIEgQKAggIAAAAEwAAAAAQa1Byb3Bvc2VkQXNzZXRJZAIAAAATX3Byb3Bvc2VkX2Fzc2V0MV9pZAAAAAAUa1Byb3Bvc2VkQXNzZXRBbW91bnQCAAAAF19wcm9wb3NlZF9hc3NldDFfYW1vdW50AAAAAA9rRGVzaXJlZEFzc2V0SWQCAAAAEV9kZXNpcmVkX2Fzc2V0X2lkAAAAAA5rRGVzaXJlZEFtb3VudAIAAAAVX2Rlc2lyZWRfYXNzZXRfYW1vdW50AAAAAAdrU3RhdHVzAgAAAAdfc3RhdHVzAAAAAAZrT3duZXICAAAABl9vd25lcgAAAAAKa0Nsb3NlVHhJZAIAAAAMX2Nsb3NlX3R4X2lkAAAAAAhrUGFydGlhbAIAAAAIX3BhcnRpYWwAAAAAB2tGaWxsZWQCAAAAB19maWxsZWQAAAAACWtQcm9wb3NhbAIAAAAFcHJvcF8AAAAADmtQcm9wb3NhbFRvdGFsAgAAAApwcm9wX3RvdGFsAAAAAAxzdGF0dXNBY3RpdmUCAAAABkFj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AAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXmTovG3", "height": 1998151, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BvVyzHw7eVDw3zbJ99HQvFS8DwX5DBVFpW84ECYtP4Xe Next: BfW7VndERmTFtJA3x9BKcKxTsk7AkGJTvbJuPEvE6aLH Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let kProposedAssetId = "_proposed_asset1_id" | |
5 | 5 | ||
6 | 6 | let kProposedAssetAmount = "_proposed_asset1_amount" | |
7 | 7 | ||
8 | - | let kDesiredAssetId = "_desired_ | |
8 | + | let kDesiredAssetId = "_desired_asset_id" | |
9 | 9 | ||
10 | - | let kDesiredAmount = "_desired_ | |
10 | + | let kDesiredAmount = "_desired_asset_amount" | |
11 | 11 | ||
12 | 12 | let kStatus = "_status" | |
13 | 13 | ||
15 | 15 | ||
16 | 16 | let kCloseTxId = "_close_tx_id" | |
17 | 17 | ||
18 | + | let kPartial = "_partial" | |
19 | + | ||
20 | + | let kFilled = "_filled" | |
21 | + | ||
22 | + | let kProposal = "prop_" | |
23 | + | ||
24 | + | let kProposalTotal = "prop_total" | |
25 | + | ||
18 | 26 | let statusActive = "Active" | |
19 | 27 | ||
20 | 28 | let statusCanceled = "Canceled" | |
21 | 29 | ||
22 | 30 | let statusDone = "Done" | |
23 | 31 | ||
24 | - | @Callable(i) | |
25 | - | func placeProposal (desireToGetAssetId,desireToGetAmount) = if ((size(i.payments) != 1)) | |
26 | - | then throw("One attached assets expected") | |
27 | - | else { | |
28 | - | let $t0603702 = $Tuple2(i.payments[0].amount, toBase58String(value(i.payments[0].assetId))) | |
29 | - | let pmtAmount = $t0603702._1 | |
30 | - | let pmtAssetId = $t0603702._2 | |
31 | - | let id = toBase58String(i.transactionId) | |
32 | - | [StringEntry((id + kOwner), toString(i.caller)), StringEntry((id + kProposedAssetId), pmtAssetId), IntegerEntry((id + kProposedAssetAmount), pmtAmount), StringEntry((id + kDesiredAssetId), desireToGetAssetId), IntegerEntry((id + kDesiredAmount), desireToGetAmount), StringEntry((id + kStatus), statusActive)] | |
33 | - | } | |
32 | + | let scale8 = 100000000 | |
34 | 33 | ||
34 | + | let poolFee = 30 | |
35 | + | ||
36 | + | let orderFee = 5 | |
37 | + | ||
38 | + | let feeDelimiter = 10000 | |
39 | + | ||
40 | + | func readProposalData (id) = { | |
41 | + | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
42 | + | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
43 | + | let proposedAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found")), "Incorrect proposed asset id") | |
44 | + | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
45 | + | let desiredAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kDesiredAssetId)), "Desired asset not found")), "Incorrect desired asset id") | |
46 | + | let desiredAssetAmount = valueOrErrorMessage(getInteger(this, (id + kDesiredAmount)), "Desired amount not found") | |
47 | + | let partialAllowed = valueOrErrorMessage(getBoolean(this, (id + kPartial)), "Partial setting isn't set") | |
48 | + | let filled = valueOrElse(getInteger(this, (id + kFilled)), 0) | |
49 | + | let txs = valueOrElse(getString(this, (id + kCloseTxId)), "") | |
50 | + | $Tuple9(status, ownerAddr, proposedAssetId, proposedAssetAmount, desiredAssetId, desiredAssetAmount, partialAllowed, filled, txs) | |
51 | + | } | |
35 | 52 | ||
36 | 53 | ||
37 | 54 | @Callable(i) | |
38 | - | func cancelProposal (id) = { | |
39 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
40 | - | if ((status != statusActive)) | |
41 | - | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
55 | + | func placeProposal (desireToGetAssetId,desireToGetAmount,partial) = { | |
56 | + | let $t019602059 = $Tuple2(i.payments[0].amount, toBase58String(value(i.payments[0].assetId))) | |
57 | + | let pmtAmount = $t019602059._1 | |
58 | + | let pmtAssetId = $t019602059._2 | |
59 | + | let id = toBase58String(i.transactionId) | |
60 | + | if (isDefined(getString(this, (id + kStatus)))) | |
61 | + | then throw("ID already registered") | |
42 | 62 | else { | |
43 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
44 | - | let proposedAssetId = valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found") | |
45 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
46 | - | if ((i.caller != ownerAddr)) | |
47 | - | then throw("Only owner can cancel") | |
48 | - | else [ScriptTransfer(ownerAddr, proposedAssetAmount, fromBase58String(proposedAssetId)), StringEntry((id + kStatus), statusCanceled), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
63 | + | let prop_total = valueOrElse(getInteger(this, kProposalTotal), 0) | |
64 | + | [StringEntry((kProposal + toString((prop_total + 1))), id), IntegerEntry(kProposalTotal, (prop_total + 1)), StringEntry((id + kOwner), toString(i.caller)), StringEntry((id + kProposedAssetId), pmtAssetId), IntegerEntry((id + kProposedAssetAmount), pmtAmount), StringEntry((id + kDesiredAssetId), desireToGetAssetId), IntegerEntry((id + kDesiredAmount), desireToGetAmount), BooleanEntry((id + kPartial), partial), StringEntry((id + kStatus), statusActive)] | |
49 | 65 | } | |
50 | 66 | } | |
51 | 67 | ||
52 | 68 | ||
53 | 69 | ||
54 | 70 | @Callable(i) | |
71 | + | func cancelProposal (id) = { | |
72 | + | let $t027962945 = readProposalData(id) | |
73 | + | let status = $t027962945._1 | |
74 | + | let ownerAddr = $t027962945._2 | |
75 | + | let proposedAssetId = $t027962945._3 | |
76 | + | let proposedAssetAmount = $t027962945._4 | |
77 | + | let desiredAssetId = $t027962945._5 | |
78 | + | let desiredAssetAmount = $t027962945._6 | |
79 | + | let partialAllowed = $t027962945._7 | |
80 | + | let filled = $t027962945._8 | |
81 | + | let txs = $t027962945._9 | |
82 | + | if ((status != statusActive)) | |
83 | + | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
84 | + | else [ScriptTransfer(ownerAddr, (proposedAssetAmount - filled), proposedAssetId), StringEntry((id + kStatus), statusCanceled), StringEntry((id + kCloseTxId), ((txs + ":") + toBase58String(i.transactionId)))] | |
85 | + | } | |
86 | + | ||
87 | + | ||
88 | + | ||
89 | + | @Callable(i) | |
55 | 90 | func acceptProposal (id) = { | |
56 | - | let $t020212104 = $Tuple2(i.payments[0].amount, value(i.payments[0].assetId)) | |
57 | - | let pmtAmount = $t020212104._1 | |
58 | - | let pmtAssetId = $t020212104._2 | |
59 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
91 | + | let $t033253408 = $Tuple2(i.payments[0].amount, value(i.payments[0].assetId)) | |
92 | + | let pmtAmount = $t033253408._1 | |
93 | + | let pmtAssetId = $t033253408._2 | |
94 | + | let $t034123561 = readProposalData(id) | |
95 | + | let status = $t034123561._1 | |
96 | + | let ownerAddr = $t034123561._2 | |
97 | + | let proposedAssetId = $t034123561._3 | |
98 | + | let proposedAssetAmount = $t034123561._4 | |
99 | + | let desiredAssetId = $t034123561._5 | |
100 | + | let desiredAssetAmount = $t034123561._6 | |
101 | + | let partialAllowed = $t034123561._7 | |
102 | + | let filled = $t034123561._8 | |
103 | + | let txs = $t034123561._9 | |
104 | + | if ((status != statusActive)) | |
105 | + | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
106 | + | else if ((desiredAssetId != pmtAssetId)) | |
107 | + | then throw("Atatched asset doesn't match desired") | |
108 | + | else { | |
109 | + | let $t037734102 = if (!(partialAllowed)) | |
110 | + | then if ((desiredAssetAmount != pmtAmount)) | |
111 | + | then throw("Attached asset amount doesn't match") | |
112 | + | else $Tuple2(pmtAmount, desiredAssetAmount) | |
113 | + | else { | |
114 | + | let a1 = min([pmtAmount, (desiredAssetAmount - filled)]) | |
115 | + | $Tuple2(a1, fraction(proposedAssetAmount, a1, desiredAssetAmount)) | |
116 | + | } | |
117 | + | let amount1 = $t037734102._1 | |
118 | + | let amount2 = $t037734102._2 | |
119 | + | let filledNew = (filled + amount1) | |
120 | + | let statusNew = if ((filledNew == desiredAssetAmount)) | |
121 | + | then statusDone | |
122 | + | else statusActive | |
123 | + | [ScriptTransfer(ownerAddr, amount1, desiredAssetId), ScriptTransfer(i.caller, amount2, proposedAssetId), ScriptTransfer(i.caller, (pmtAmount - amount1), desiredAssetId), IntegerEntry((id + kFilled), filledNew), StringEntry((id + kStatus), statusNew), StringEntry((id + kCloseTxId), ((txs + ":") + toBase58String(i.transactionId)))] | |
124 | + | } | |
125 | + | } | |
126 | + | ||
127 | + | ||
128 | + | ||
129 | + | @Callable(i) | |
130 | + | func matchProposals (id1,id2) = { | |
131 | + | let $t046504809 = readProposalData(id1) | |
132 | + | let status1 = $t046504809._1 | |
133 | + | let ownerAddr1 = $t046504809._2 | |
134 | + | let proposedAssetId1 = $t046504809._3 | |
135 | + | let proposedAssetAmount1 = $t046504809._4 | |
136 | + | let desiredAssetId1 = $t046504809._5 | |
137 | + | let desiredAssetAmount1 = $t046504809._6 | |
138 | + | let partialAllowed1 = $t046504809._7 | |
139 | + | let filled1 = $t046504809._8 | |
140 | + | let txs1 = $t046504809._9 | |
141 | + | let $t048124971 = readProposalData(id2) | |
142 | + | let status2 = $t048124971._1 | |
143 | + | let ownerAddr2 = $t048124971._2 | |
144 | + | let proposedAssetId2 = $t048124971._3 | |
145 | + | let proposedAssetAmount2 = $t048124971._4 | |
146 | + | let desiredAssetId2 = $t048124971._5 | |
147 | + | let desiredAssetAmount2 = $t048124971._6 | |
148 | + | let partialAllowed2 = $t048124971._7 | |
149 | + | let filled2 = $t048124971._8 | |
150 | + | let txs2 = $t048124971._9 | |
151 | + | if ((status1 != statusActive)) | |
152 | + | then throw(((("Proposal with id '" + id1) + "' is not active. Status: ") + status1)) | |
153 | + | else if ((status2 != statusActive)) | |
154 | + | then throw(((("Proposal with id '" + id2) + "' is not active. Status: ") + status2)) | |
155 | + | else if (if ((desiredAssetId1 != proposedAssetId2)) | |
156 | + | then true | |
157 | + | else (desiredAssetId2 != proposedAssetId1)) | |
158 | + | then throw("Assets in proposals doesn't match") | |
159 | + | else { | |
160 | + | let price1 = fraction(proposedAssetAmount1, scale8, desiredAssetAmount1) | |
161 | + | let price2 = fraction(desiredAssetAmount2, scale8, proposedAssetAmount2) | |
162 | + | if ((price2 > price1)) | |
163 | + | then throw(((("Price doesn't match. price1 = " + toString(price1)) + ", price2 = ") + toString(price2))) | |
164 | + | else { | |
165 | + | let usedPrice = ((price1 + price2) / 2) | |
166 | + | let amount0 = min([proposedAssetAmount1, (desiredAssetAmount2 - filled2)]) | |
167 | + | let amount2 = min([fraction(amount0, scale8, usedPrice), (desiredAssetAmount1 - filled1)]) | |
168 | + | let amount1 = fraction(amount2, usedPrice, scale8) | |
169 | + | let newFilled1 = (filled1 + amount2) | |
170 | + | let newFilled2 = (filled2 + amount1) | |
171 | + | let result0 = [ScriptTransfer(ownerAddr1, amount2, desiredAssetId1), ScriptTransfer(ownerAddr2, amount1, desiredAssetId2), IntegerEntry((id1 + kFilled), newFilled1), IntegerEntry((id2 + kFilled), newFilled2), StringEntry((id1 + kCloseTxId), ((txs1 + ":") + toBase58String(i.transactionId))), StringEntry((id2 + kCloseTxId), ((txs2 + ":") + toBase58String(i.transactionId)))] | |
172 | + | func appendResult (r0,ownerAddr,id,proposedAmountLeft,desiredAmountLeft,proposedAssetId) = if (if ((0 > proposedAmountLeft)) | |
173 | + | then true | |
174 | + | else (0 > desiredAmountLeft)) | |
175 | + | then throw("Internal error with calculation") | |
176 | + | else if ((proposedAmountLeft == 0)) | |
177 | + | then (r0 :+ StringEntry((id + kStatus), statusDone)) | |
178 | + | else if ((desiredAmountLeft == 0)) | |
179 | + | then (r0 ++ [ScriptTransfer(ownerAddr, proposedAmountLeft, proposedAssetId), StringEntry((id + kStatus), statusDone)]) | |
180 | + | else r0 | |
181 | + | ||
182 | + | let proposedAmountLeft1 = (proposedAssetAmount1 - amount1) | |
183 | + | let desiredAmountLeft1 = (desiredAssetAmount1 - amount2) | |
184 | + | let proposedAmountLeft2 = (proposedAssetAmount1 - amount2) | |
185 | + | let desiredAmountLeft2 = (desiredAssetAmount1 - amount1) | |
186 | + | let result1 = appendResult(result0, ownerAddr1, id1, proposedAmountLeft1, desiredAmountLeft1, proposedAssetId1) | |
187 | + | let result2 = appendResult(result1, ownerAddr2, id2, proposedAmountLeft2, desiredAmountLeft2, proposedAssetId2) | |
188 | + | result2 | |
189 | + | } | |
190 | + | } | |
191 | + | } | |
192 | + | ||
193 | + | ||
194 | + | ||
195 | + | @Callable(i) | |
196 | + | func executeOnSwopfi (id,pool) = { | |
197 | + | let $t080108159 = readProposalData(id) | |
198 | + | let status = $t080108159._1 | |
199 | + | let ownerAddr = $t080108159._2 | |
200 | + | let proposedAssetId = $t080108159._3 | |
201 | + | let proposedAssetAmount = $t080108159._4 | |
202 | + | let desiredAssetId = $t080108159._5 | |
203 | + | let desiredAssetAmount = $t080108159._6 | |
204 | + | let partialAllowed = $t080108159._7 | |
205 | + | let filled = $t080108159._8 | |
206 | + | let txs = $t080108159._9 | |
60 | 207 | if ((status != statusActive)) | |
61 | 208 | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
62 | 209 | else { | |
63 | - | let desiredAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kDesiredAssetId)), "Desired asset not found")), "Incorrect desired asset id") | |
64 | - | let desiredAssetAmount = valueOrErrorMessage(getInteger(this, (id + kDesiredAmount)), "Desired amount not found") | |
65 | - | if ((desiredAssetId != pmtAssetId)) | |
66 | - | then throw("Atatched asset doesn't match desired") | |
67 | - | else if ((desiredAssetAmount != pmtAmount)) | |
68 | - | then throw("Attached asset amount doesn't match") | |
69 | - | else { | |
70 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
71 | - | let proposedAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found")), "Incorrect proposed asset id") | |
72 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
73 | - | [ScriptTransfer(ownerAddr, desiredAssetAmount, desiredAssetId), ScriptTransfer(i.caller, proposedAssetAmount, proposedAssetId), StringEntry((id + kStatus), statusDone), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
74 | - | } | |
210 | + | let poolAddr = valueOrErrorMessage(addressFromString(pool), "Wrong pool address") | |
211 | + | let poolAssetA = getStringValue(poolAddr, "A_asset_id") | |
212 | + | let poolAssetB = getStringValue(poolAddr, "B_asset_id") | |
213 | + | let proposedAssetId1 = "" | |
214 | + | let desiredAssetId1 = "" | |
215 | + | let t = if (if ((poolAssetA == proposedAssetId1)) | |
216 | + | then (poolAssetB == desiredAssetId1) | |
217 | + | else false) | |
218 | + | then 1 | |
219 | + | else if (if ((poolAssetB == proposedAssetId1)) | |
220 | + | then (poolAssetA == desiredAssetId1) | |
221 | + | else false) | |
222 | + | then 2 | |
223 | + | else throw("Pool doesn't match proposal") | |
224 | + | let poolBalA = getIntegerValue(poolAddr, "A_asset_balance") | |
225 | + | let poolBalB = getIntegerValue(poolAddr, "B_asset_balance") | |
226 | + | let bal1 = if ((t == 1)) | |
227 | + | then poolBalA | |
228 | + | else poolBalB | |
229 | + | let bal2 = if ((t == 1)) | |
230 | + | then poolBalB | |
231 | + | else poolBalA | |
232 | + | let ratio = fraction(desiredAssetAmount, scale8, proposedAssetAmount) | |
233 | + | let maxPay = (fraction(bal2, (((feeDelimiter - poolFee) - orderFee) * scale8), (feeDelimiter * ratio)) - bal1) | |
234 | + | let toPay = min([maxPay, proposedAssetAmount]) | |
235 | + | let toGet = fraction(bal2, toPay, (bal1 + toPay)) | |
236 | + | nil | |
75 | 237 | } | |
76 | 238 | } | |
77 | 239 |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let kProposedAssetId = "_proposed_asset1_id" | |
5 | 5 | ||
6 | 6 | let kProposedAssetAmount = "_proposed_asset1_amount" | |
7 | 7 | ||
8 | - | let kDesiredAssetId = "_desired_ | |
8 | + | let kDesiredAssetId = "_desired_asset_id" | |
9 | 9 | ||
10 | - | let kDesiredAmount = "_desired_ | |
10 | + | let kDesiredAmount = "_desired_asset_amount" | |
11 | 11 | ||
12 | 12 | let kStatus = "_status" | |
13 | 13 | ||
14 | 14 | let kOwner = "_owner" | |
15 | 15 | ||
16 | 16 | let kCloseTxId = "_close_tx_id" | |
17 | 17 | ||
18 | + | let kPartial = "_partial" | |
19 | + | ||
20 | + | let kFilled = "_filled" | |
21 | + | ||
22 | + | let kProposal = "prop_" | |
23 | + | ||
24 | + | let kProposalTotal = "prop_total" | |
25 | + | ||
18 | 26 | let statusActive = "Active" | |
19 | 27 | ||
20 | 28 | let statusCanceled = "Canceled" | |
21 | 29 | ||
22 | 30 | let statusDone = "Done" | |
23 | 31 | ||
24 | - | @Callable(i) | |
25 | - | func placeProposal (desireToGetAssetId,desireToGetAmount) = if ((size(i.payments) != 1)) | |
26 | - | then throw("One attached assets expected") | |
27 | - | else { | |
28 | - | let $t0603702 = $Tuple2(i.payments[0].amount, toBase58String(value(i.payments[0].assetId))) | |
29 | - | let pmtAmount = $t0603702._1 | |
30 | - | let pmtAssetId = $t0603702._2 | |
31 | - | let id = toBase58String(i.transactionId) | |
32 | - | [StringEntry((id + kOwner), toString(i.caller)), StringEntry((id + kProposedAssetId), pmtAssetId), IntegerEntry((id + kProposedAssetAmount), pmtAmount), StringEntry((id + kDesiredAssetId), desireToGetAssetId), IntegerEntry((id + kDesiredAmount), desireToGetAmount), StringEntry((id + kStatus), statusActive)] | |
33 | - | } | |
32 | + | let scale8 = 100000000 | |
34 | 33 | ||
34 | + | let poolFee = 30 | |
35 | + | ||
36 | + | let orderFee = 5 | |
37 | + | ||
38 | + | let feeDelimiter = 10000 | |
39 | + | ||
40 | + | func readProposalData (id) = { | |
41 | + | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
42 | + | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
43 | + | let proposedAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found")), "Incorrect proposed asset id") | |
44 | + | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
45 | + | let desiredAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kDesiredAssetId)), "Desired asset not found")), "Incorrect desired asset id") | |
46 | + | let desiredAssetAmount = valueOrErrorMessage(getInteger(this, (id + kDesiredAmount)), "Desired amount not found") | |
47 | + | let partialAllowed = valueOrErrorMessage(getBoolean(this, (id + kPartial)), "Partial setting isn't set") | |
48 | + | let filled = valueOrElse(getInteger(this, (id + kFilled)), 0) | |
49 | + | let txs = valueOrElse(getString(this, (id + kCloseTxId)), "") | |
50 | + | $Tuple9(status, ownerAddr, proposedAssetId, proposedAssetAmount, desiredAssetId, desiredAssetAmount, partialAllowed, filled, txs) | |
51 | + | } | |
35 | 52 | ||
36 | 53 | ||
37 | 54 | @Callable(i) | |
38 | - | func cancelProposal (id) = { | |
39 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
40 | - | if ((status != statusActive)) | |
41 | - | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
55 | + | func placeProposal (desireToGetAssetId,desireToGetAmount,partial) = { | |
56 | + | let $t019602059 = $Tuple2(i.payments[0].amount, toBase58String(value(i.payments[0].assetId))) | |
57 | + | let pmtAmount = $t019602059._1 | |
58 | + | let pmtAssetId = $t019602059._2 | |
59 | + | let id = toBase58String(i.transactionId) | |
60 | + | if (isDefined(getString(this, (id + kStatus)))) | |
61 | + | then throw("ID already registered") | |
42 | 62 | else { | |
43 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
44 | - | let proposedAssetId = valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found") | |
45 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
46 | - | if ((i.caller != ownerAddr)) | |
47 | - | then throw("Only owner can cancel") | |
48 | - | else [ScriptTransfer(ownerAddr, proposedAssetAmount, fromBase58String(proposedAssetId)), StringEntry((id + kStatus), statusCanceled), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
63 | + | let prop_total = valueOrElse(getInteger(this, kProposalTotal), 0) | |
64 | + | [StringEntry((kProposal + toString((prop_total + 1))), id), IntegerEntry(kProposalTotal, (prop_total + 1)), StringEntry((id + kOwner), toString(i.caller)), StringEntry((id + kProposedAssetId), pmtAssetId), IntegerEntry((id + kProposedAssetAmount), pmtAmount), StringEntry((id + kDesiredAssetId), desireToGetAssetId), IntegerEntry((id + kDesiredAmount), desireToGetAmount), BooleanEntry((id + kPartial), partial), StringEntry((id + kStatus), statusActive)] | |
49 | 65 | } | |
50 | 66 | } | |
51 | 67 | ||
52 | 68 | ||
53 | 69 | ||
54 | 70 | @Callable(i) | |
71 | + | func cancelProposal (id) = { | |
72 | + | let $t027962945 = readProposalData(id) | |
73 | + | let status = $t027962945._1 | |
74 | + | let ownerAddr = $t027962945._2 | |
75 | + | let proposedAssetId = $t027962945._3 | |
76 | + | let proposedAssetAmount = $t027962945._4 | |
77 | + | let desiredAssetId = $t027962945._5 | |
78 | + | let desiredAssetAmount = $t027962945._6 | |
79 | + | let partialAllowed = $t027962945._7 | |
80 | + | let filled = $t027962945._8 | |
81 | + | let txs = $t027962945._9 | |
82 | + | if ((status != statusActive)) | |
83 | + | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
84 | + | else [ScriptTransfer(ownerAddr, (proposedAssetAmount - filled), proposedAssetId), StringEntry((id + kStatus), statusCanceled), StringEntry((id + kCloseTxId), ((txs + ":") + toBase58String(i.transactionId)))] | |
85 | + | } | |
86 | + | ||
87 | + | ||
88 | + | ||
89 | + | @Callable(i) | |
55 | 90 | func acceptProposal (id) = { | |
56 | - | let $t020212104 = $Tuple2(i.payments[0].amount, value(i.payments[0].assetId)) | |
57 | - | let pmtAmount = $t020212104._1 | |
58 | - | let pmtAssetId = $t020212104._2 | |
59 | - | let status = valueOrErrorMessage(getString(this, (id + kStatus)), (("Proposal with id '" + id) + "' not found")) | |
91 | + | let $t033253408 = $Tuple2(i.payments[0].amount, value(i.payments[0].assetId)) | |
92 | + | let pmtAmount = $t033253408._1 | |
93 | + | let pmtAssetId = $t033253408._2 | |
94 | + | let $t034123561 = readProposalData(id) | |
95 | + | let status = $t034123561._1 | |
96 | + | let ownerAddr = $t034123561._2 | |
97 | + | let proposedAssetId = $t034123561._3 | |
98 | + | let proposedAssetAmount = $t034123561._4 | |
99 | + | let desiredAssetId = $t034123561._5 | |
100 | + | let desiredAssetAmount = $t034123561._6 | |
101 | + | let partialAllowed = $t034123561._7 | |
102 | + | let filled = $t034123561._8 | |
103 | + | let txs = $t034123561._9 | |
104 | + | if ((status != statusActive)) | |
105 | + | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
106 | + | else if ((desiredAssetId != pmtAssetId)) | |
107 | + | then throw("Atatched asset doesn't match desired") | |
108 | + | else { | |
109 | + | let $t037734102 = if (!(partialAllowed)) | |
110 | + | then if ((desiredAssetAmount != pmtAmount)) | |
111 | + | then throw("Attached asset amount doesn't match") | |
112 | + | else $Tuple2(pmtAmount, desiredAssetAmount) | |
113 | + | else { | |
114 | + | let a1 = min([pmtAmount, (desiredAssetAmount - filled)]) | |
115 | + | $Tuple2(a1, fraction(proposedAssetAmount, a1, desiredAssetAmount)) | |
116 | + | } | |
117 | + | let amount1 = $t037734102._1 | |
118 | + | let amount2 = $t037734102._2 | |
119 | + | let filledNew = (filled + amount1) | |
120 | + | let statusNew = if ((filledNew == desiredAssetAmount)) | |
121 | + | then statusDone | |
122 | + | else statusActive | |
123 | + | [ScriptTransfer(ownerAddr, amount1, desiredAssetId), ScriptTransfer(i.caller, amount2, proposedAssetId), ScriptTransfer(i.caller, (pmtAmount - amount1), desiredAssetId), IntegerEntry((id + kFilled), filledNew), StringEntry((id + kStatus), statusNew), StringEntry((id + kCloseTxId), ((txs + ":") + toBase58String(i.transactionId)))] | |
124 | + | } | |
125 | + | } | |
126 | + | ||
127 | + | ||
128 | + | ||
129 | + | @Callable(i) | |
130 | + | func matchProposals (id1,id2) = { | |
131 | + | let $t046504809 = readProposalData(id1) | |
132 | + | let status1 = $t046504809._1 | |
133 | + | let ownerAddr1 = $t046504809._2 | |
134 | + | let proposedAssetId1 = $t046504809._3 | |
135 | + | let proposedAssetAmount1 = $t046504809._4 | |
136 | + | let desiredAssetId1 = $t046504809._5 | |
137 | + | let desiredAssetAmount1 = $t046504809._6 | |
138 | + | let partialAllowed1 = $t046504809._7 | |
139 | + | let filled1 = $t046504809._8 | |
140 | + | let txs1 = $t046504809._9 | |
141 | + | let $t048124971 = readProposalData(id2) | |
142 | + | let status2 = $t048124971._1 | |
143 | + | let ownerAddr2 = $t048124971._2 | |
144 | + | let proposedAssetId2 = $t048124971._3 | |
145 | + | let proposedAssetAmount2 = $t048124971._4 | |
146 | + | let desiredAssetId2 = $t048124971._5 | |
147 | + | let desiredAssetAmount2 = $t048124971._6 | |
148 | + | let partialAllowed2 = $t048124971._7 | |
149 | + | let filled2 = $t048124971._8 | |
150 | + | let txs2 = $t048124971._9 | |
151 | + | if ((status1 != statusActive)) | |
152 | + | then throw(((("Proposal with id '" + id1) + "' is not active. Status: ") + status1)) | |
153 | + | else if ((status2 != statusActive)) | |
154 | + | then throw(((("Proposal with id '" + id2) + "' is not active. Status: ") + status2)) | |
155 | + | else if (if ((desiredAssetId1 != proposedAssetId2)) | |
156 | + | then true | |
157 | + | else (desiredAssetId2 != proposedAssetId1)) | |
158 | + | then throw("Assets in proposals doesn't match") | |
159 | + | else { | |
160 | + | let price1 = fraction(proposedAssetAmount1, scale8, desiredAssetAmount1) | |
161 | + | let price2 = fraction(desiredAssetAmount2, scale8, proposedAssetAmount2) | |
162 | + | if ((price2 > price1)) | |
163 | + | then throw(((("Price doesn't match. price1 = " + toString(price1)) + ", price2 = ") + toString(price2))) | |
164 | + | else { | |
165 | + | let usedPrice = ((price1 + price2) / 2) | |
166 | + | let amount0 = min([proposedAssetAmount1, (desiredAssetAmount2 - filled2)]) | |
167 | + | let amount2 = min([fraction(amount0, scale8, usedPrice), (desiredAssetAmount1 - filled1)]) | |
168 | + | let amount1 = fraction(amount2, usedPrice, scale8) | |
169 | + | let newFilled1 = (filled1 + amount2) | |
170 | + | let newFilled2 = (filled2 + amount1) | |
171 | + | let result0 = [ScriptTransfer(ownerAddr1, amount2, desiredAssetId1), ScriptTransfer(ownerAddr2, amount1, desiredAssetId2), IntegerEntry((id1 + kFilled), newFilled1), IntegerEntry((id2 + kFilled), newFilled2), StringEntry((id1 + kCloseTxId), ((txs1 + ":") + toBase58String(i.transactionId))), StringEntry((id2 + kCloseTxId), ((txs2 + ":") + toBase58String(i.transactionId)))] | |
172 | + | func appendResult (r0,ownerAddr,id,proposedAmountLeft,desiredAmountLeft,proposedAssetId) = if (if ((0 > proposedAmountLeft)) | |
173 | + | then true | |
174 | + | else (0 > desiredAmountLeft)) | |
175 | + | then throw("Internal error with calculation") | |
176 | + | else if ((proposedAmountLeft == 0)) | |
177 | + | then (r0 :+ StringEntry((id + kStatus), statusDone)) | |
178 | + | else if ((desiredAmountLeft == 0)) | |
179 | + | then (r0 ++ [ScriptTransfer(ownerAddr, proposedAmountLeft, proposedAssetId), StringEntry((id + kStatus), statusDone)]) | |
180 | + | else r0 | |
181 | + | ||
182 | + | let proposedAmountLeft1 = (proposedAssetAmount1 - amount1) | |
183 | + | let desiredAmountLeft1 = (desiredAssetAmount1 - amount2) | |
184 | + | let proposedAmountLeft2 = (proposedAssetAmount1 - amount2) | |
185 | + | let desiredAmountLeft2 = (desiredAssetAmount1 - amount1) | |
186 | + | let result1 = appendResult(result0, ownerAddr1, id1, proposedAmountLeft1, desiredAmountLeft1, proposedAssetId1) | |
187 | + | let result2 = appendResult(result1, ownerAddr2, id2, proposedAmountLeft2, desiredAmountLeft2, proposedAssetId2) | |
188 | + | result2 | |
189 | + | } | |
190 | + | } | |
191 | + | } | |
192 | + | ||
193 | + | ||
194 | + | ||
195 | + | @Callable(i) | |
196 | + | func executeOnSwopfi (id,pool) = { | |
197 | + | let $t080108159 = readProposalData(id) | |
198 | + | let status = $t080108159._1 | |
199 | + | let ownerAddr = $t080108159._2 | |
200 | + | let proposedAssetId = $t080108159._3 | |
201 | + | let proposedAssetAmount = $t080108159._4 | |
202 | + | let desiredAssetId = $t080108159._5 | |
203 | + | let desiredAssetAmount = $t080108159._6 | |
204 | + | let partialAllowed = $t080108159._7 | |
205 | + | let filled = $t080108159._8 | |
206 | + | let txs = $t080108159._9 | |
60 | 207 | if ((status != statusActive)) | |
61 | 208 | then throw(((("Proposal with id '" + id) + "' is not active. Status: ") + status)) | |
62 | 209 | else { | |
63 | - | let desiredAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kDesiredAssetId)), "Desired asset not found")), "Incorrect desired asset id") | |
64 | - | let desiredAssetAmount = valueOrErrorMessage(getInteger(this, (id + kDesiredAmount)), "Desired amount not found") | |
65 | - | if ((desiredAssetId != pmtAssetId)) | |
66 | - | then throw("Atatched asset doesn't match desired") | |
67 | - | else if ((desiredAssetAmount != pmtAmount)) | |
68 | - | then throw("Attached asset amount doesn't match") | |
69 | - | else { | |
70 | - | let ownerAddr = addressFromStringValue(valueOrErrorMessage(getString(this, (id + kOwner)), "owner not set")) | |
71 | - | let proposedAssetId = valueOrErrorMessage(fromBase58String(valueOrErrorMessage(getString(this, (id + kProposedAssetId)), "Proposed asset not found")), "Incorrect proposed asset id") | |
72 | - | let proposedAssetAmount = valueOrErrorMessage(getInteger(this, (id + kProposedAssetAmount)), "Proposed amount not found") | |
73 | - | [ScriptTransfer(ownerAddr, desiredAssetAmount, desiredAssetId), ScriptTransfer(i.caller, proposedAssetAmount, proposedAssetId), StringEntry((id + kStatus), statusDone), StringEntry((id + kCloseTxId), toBase58String(i.transactionId))] | |
74 | - | } | |
210 | + | let poolAddr = valueOrErrorMessage(addressFromString(pool), "Wrong pool address") | |
211 | + | let poolAssetA = getStringValue(poolAddr, "A_asset_id") | |
212 | + | let poolAssetB = getStringValue(poolAddr, "B_asset_id") | |
213 | + | let proposedAssetId1 = "" | |
214 | + | let desiredAssetId1 = "" | |
215 | + | let t = if (if ((poolAssetA == proposedAssetId1)) | |
216 | + | then (poolAssetB == desiredAssetId1) | |
217 | + | else false) | |
218 | + | then 1 | |
219 | + | else if (if ((poolAssetB == proposedAssetId1)) | |
220 | + | then (poolAssetA == desiredAssetId1) | |
221 | + | else false) | |
222 | + | then 2 | |
223 | + | else throw("Pool doesn't match proposal") | |
224 | + | let poolBalA = getIntegerValue(poolAddr, "A_asset_balance") | |
225 | + | let poolBalB = getIntegerValue(poolAddr, "B_asset_balance") | |
226 | + | let bal1 = if ((t == 1)) | |
227 | + | then poolBalA | |
228 | + | else poolBalB | |
229 | + | let bal2 = if ((t == 1)) | |
230 | + | then poolBalB | |
231 | + | else poolBalA | |
232 | + | let ratio = fraction(desiredAssetAmount, scale8, proposedAssetAmount) | |
233 | + | let maxPay = (fraction(bal2, (((feeDelimiter - poolFee) - orderFee) * scale8), (feeDelimiter * ratio)) - bal1) | |
234 | + | let toPay = min([maxPay, proposedAssetAmount]) | |
235 | + | let toGet = fraction(bal2, toPay, (bal1 + toPay)) | |
236 | + | nil | |
75 | 237 | } | |
76 | 238 | } | |
77 | 239 | ||
78 | 240 | ||
79 | 241 | @Verifier(tx) | |
80 | 242 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
81 | 243 |
github/deemru/w8io/026f985 52.21 ms ◑