tx · BhtDQohiKkmDXtbykyPeSSUBVRmUDQsXJLhTrce6GdcZ 3N5Xd7QVQZWntaJwha9Kg42is626GUPjtUW: -0.01400000 Waves 2021.04.02 15:01 [1464797] smart account 3N5Xd7QVQZWntaJwha9Kg42is626GUPjtUW > SELF 0.00000000 Waves
{ "type": 13, "id": "BhtDQohiKkmDXtbykyPeSSUBVRmUDQsXJLhTrce6GdcZ", "fee": 1400000, "feeAssetId": null, "timestamp": 1617364964580, "version": 2, "chainId": 84, "sender": "3N5Xd7QVQZWntaJwha9Kg42is626GUPjtUW", "senderPublicKey": "DfbjpZJBbZwnUKysUkxCbWTE1ZWuoUb6Y6BZdu5iAE8j", "proofs": [ "2UmukAFyMLQ2hWJz8jhFTutjwEesFXFQgA7BaSWLiHoTEZKtKVDyW9ZT9R5dDgjpkER5pkvau3JdcpWYCV8oLuux" ], "script": "base64:AAIEAAAAAAAAABkIAhIAEgMKAQESABIDCgEBEgASABIDCgEBAAAAMwAAAAAHdmVyc2lvbgIAAAAFMS4wLjAAAAAACmtleVZlcnNpb24CAAAAB3ZlcnNpb24AAAAACWtleUFjdGl2ZQIAAAAGYWN0aXZlAAAAAAtrZXlBc3NldElkQQIAAAAKQV9hc3NldF9pZAAAAAALa2V5QXNzZXRJZEICAAAACkJfYXNzZXRfaWQAAAAAC2tleUJhbGFuY2VBAgAAAA9BX2Fzc2V0X2JhbGFuY2UAAAAAC2tleUJhbGFuY2VCAgAAAA9CX2Fzc2V0X2JhbGFuY2UAAAAAD2tleVNoYXJlQXNzZXRJZAIAAAAOc2hhcmVfYXNzZXRfaWQAAAAAE2tleVNoYXJlQXNzZXRTdXBwbHkCAAAAEnNoYXJlX2Fzc2V0X3N1cHBseQAAAAANa2V5Q29tbWlzc2lvbgIAAAAKY29tbWlzc2lvbgAAAAAba2V5Q29tbWlzc2lvblNjYWxlRGVsaW1pdGVyAgAAABpjb21taXNzaW9uX3NjYWxlX2RlbGltaXRlcgAAAAAIa2V5Q2F1c2UCAAAADn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AAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAUAAAAMYWRtaW5QdWJLZXkyBgkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAFAAAADGFkbWluUHViS2V5MwYJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAABQAAABJhZG1pblB1YktleVN0YWtpbmcDBQAAABNjYWxsVGFrZUludG9BY2NvdW50BgUAAAALY2FsbFN0YWtpbmcJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5tf5rZA==", "height": 1464797, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 2KpywD9ZTExTSbp5XBeFruo52nGKsGDiWJJeNNgifsH9 Next: 3Hy5xeUQU913zh36UtTvQFyYANpC5RcEyJ4ssSX8tEHs Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let version = " | |
4 | + | let version = "1.0.0" | |
5 | 5 | ||
6 | - | let | |
6 | + | let keyVersion = "version" | |
7 | 7 | ||
8 | - | let | |
8 | + | let keyActive = "active" | |
9 | 9 | ||
10 | - | let | |
10 | + | let keyAssetIdA = "A_asset_id" | |
11 | 11 | ||
12 | - | let | |
12 | + | let keyAssetIdB = "B_asset_id" | |
13 | 13 | ||
14 | - | let | |
14 | + | let keyBalanceA = "A_asset_balance" | |
15 | 15 | ||
16 | - | let | |
16 | + | let keyBalanceB = "B_asset_balance" | |
17 | 17 | ||
18 | - | let | |
18 | + | let keyShareAssetId = "share_asset_id" | |
19 | 19 | ||
20 | - | let | |
20 | + | let keyShareAssetSupply = "share_asset_supply" | |
21 | 21 | ||
22 | - | let | |
22 | + | let keyCommission = "commission" | |
23 | 23 | ||
24 | - | let | |
24 | + | let keyCommissionScaleDelimiter = "commission_scale_delimiter" | |
25 | 25 | ||
26 | - | let | |
26 | + | let keyCause = "shutdown_cause" | |
27 | 27 | ||
28 | - | let | |
28 | + | let adminPubKey1 = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
29 | 29 | ||
30 | - | let | |
30 | + | let adminPubKey2 = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
31 | 31 | ||
32 | - | let | |
32 | + | let adminPubKey3 = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
33 | 33 | ||
34 | - | let | |
34 | + | let adminPubKeyStartStop = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
35 | 35 | ||
36 | - | let | |
36 | + | let adminPubKeyStaking = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
37 | 37 | ||
38 | - | let | |
38 | + | let governanceAddress = Address(base58'3NAGTtZz6WpupSN89NZD5rMZwwziZEg4Kx4') | |
39 | 39 | ||
40 | - | let govAddr = Address(base58'3NAGTtZz6WpupSN89NZD5rMZwwziZEg4Kx4') | |
41 | - | ||
42 | - | let stakingAddress = Address(base58'3ND2G6RdHNnSNUzyPsWhQ6L7pEUUAyfrWzo') | |
40 | + | let stakingAddress = Address(base58'3N6q7sCGSSLBUXDdjBdYGTJbZGZfhhh8cNg') | |
43 | 41 | ||
44 | 42 | let USDN = base58'8UrfDVd5GreeUwm7uPk7eYz1eMv376kzR52C6sANPkwS' | |
45 | 43 | ||
46 | 44 | let stakingFeeInUSDN = (9 * value(value(assetInfo(USDN)).minSponsoredFee)) | |
47 | 45 | ||
48 | - | let isActive = getBooleanValue(this, | |
46 | + | let isActive = getBooleanValue(this, keyActive) | |
49 | 47 | ||
50 | - | let strAssetIdA = getStringValue(this, | |
48 | + | let strAssetIdA = getStringValue(this, keyAssetIdA) | |
51 | 49 | ||
52 | - | let strAssetIdB = getStringValue(this, | |
50 | + | let strAssetIdB = getStringValue(this, keyAssetIdB) | |
53 | 51 | ||
54 | 52 | let assetIdA = if ((strAssetIdA == "WAVES")) | |
55 | 53 | then unit | |
77 | 75 | throw("Match error") | |
78 | 76 | } | |
79 | 77 | ||
80 | - | let balanceA = getIntegerValue(this, | |
78 | + | let balanceA = getIntegerValue(this, keyBalanceA) | |
81 | 79 | ||
82 | - | let balanceB = getIntegerValue(this, | |
80 | + | let balanceB = getIntegerValue(this, keyBalanceB) | |
83 | 81 | ||
84 | - | let shareAssetId = fromBase58String(getStringValue(this, | |
82 | + | let shareAssetId = fromBase58String(getStringValue(this, keyShareAssetId)) | |
85 | 83 | ||
86 | - | let shareAssetSupply = getIntegerValue(this, | |
84 | + | let shareAssetSupply = getIntegerValue(this, keyShareAssetSupply) | |
87 | 85 | ||
88 | - | let | |
86 | + | let commission = 3000 | |
89 | 87 | ||
90 | - | let | |
88 | + | let commissionGovernance = 1200 | |
91 | 89 | ||
92 | - | let | |
90 | + | let commissionScaleDelimiter = 1000000 | |
93 | 91 | ||
94 | - | let | |
92 | + | let scaleValue3 = 1000 | |
95 | 93 | ||
96 | - | let | |
94 | + | let scaleValue8 = 100000000 | |
97 | 95 | ||
98 | - | let | |
96 | + | let slippageToleranceDelimiter = 1000 | |
99 | 97 | ||
100 | - | let scale12 = 1000000000000 | |
101 | - | ||
102 | - | let slippageScale3 = 1000 | |
103 | - | ||
104 | - | let digits8 = 8 | |
105 | - | ||
106 | - | let dAppThreshold = 50 | |
107 | - | ||
108 | - | let dAppThresholdScale2 = 100 | |
109 | - | ||
110 | - | let exchangeRatioLimitMin = 90000000 | |
111 | - | ||
112 | - | let exchangeRatioLimitMax = 110000000 | |
113 | - | ||
114 | - | let alpha = 50 | |
115 | - | ||
116 | - | let alphaDigits = 2 | |
117 | - | ||
118 | - | let beta = 46000000 | |
98 | + | let scaleValue8Digits = 8 | |
119 | 99 | ||
120 | 100 | func accountBalance (assetId) = match assetId { | |
121 | 101 | case id: ByteVector => | |
156 | 136 | then (accountBalanceWithStakedB >= balanceB) | |
157 | 137 | else false | |
158 | 138 | ||
159 | - | func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000) | |
160 | - | ||
161 | - | ||
162 | - | func invariantCalc (x,y) = { | |
163 | - | let sk = skewness(x, y) | |
164 | - | (fraction((x + y), scale8, pow(sk, digits8, alpha, alphaDigits, digits8, UP)) + (2 * fraction(pow(fraction(x, y, scale8), 0, 5, 1, (digits8 / 2), DOWN), pow((sk - beta), digits8, alpha, alphaDigits, digits8, DOWN), scale8))) | |
165 | - | } | |
166 | - | ||
167 | - | ||
168 | - | func calculateSendAmount (amountToSendEstimated,minTokenReceiveAmount,tokenReceiveAmount,tokenId) = { | |
169 | - | let slippageValue = (scale8 - ((scale8 * 1) / 10000000)) | |
170 | - | let deltaBetweenMaxAndMinSendValue = (amountToSendEstimated - minTokenReceiveAmount) | |
171 | - | let x = (balanceA + tokenReceiveAmount) | |
172 | - | let y = (balanceB + tokenReceiveAmount) | |
173 | - | let invariantNew = if ((tokenId == assetIdA)) | |
174 | - | then invariantCalc(x, (balanceB - amountToSendEstimated)) | |
175 | - | else if ((tokenId == assetIdB)) | |
176 | - | then invariantCalc((balanceA - amountToSendEstimated), y) | |
177 | - | else throw("Wrong asset in payment") | |
178 | - | let invariantEstimatedRatio = fraction(scale8, invariant, invariantNew) | |
179 | - | func getStepAmount (acc,step) = if ((acc == -1)) | |
180 | - | then { | |
181 | - | let amountToSend = (amountToSendEstimated - ((step * deltaBetweenMaxAndMinSendValue) / 5)) | |
182 | - | let stepInvariant = if ((tokenId == assetIdA)) | |
183 | - | then invariantCalc(x, (balanceB - amountToSend)) | |
184 | - | else invariantCalc((balanceA - amountToSend), y) | |
185 | - | if ((stepInvariant > invariant)) | |
186 | - | then amountToSend | |
187 | - | else -1 | |
188 | - | } | |
189 | - | else acc | |
190 | - | ||
191 | - | let stepAmount = { | |
192 | - | let $list56715714 = [1, 2, 3, 4, 5] | |
193 | - | let $size56715714 = size($list56715714) | |
194 | - | let $acc056715714 = -1 | |
195 | - | if (($size56715714 == 0)) | |
196 | - | then $acc056715714 | |
197 | - | else { | |
198 | - | let $acc156715714 = getStepAmount($acc056715714, $list56715714[0]) | |
199 | - | if (($size56715714 == 1)) | |
200 | - | then $acc156715714 | |
201 | - | else { | |
202 | - | let $acc256715714 = getStepAmount($acc156715714, $list56715714[1]) | |
203 | - | if (($size56715714 == 2)) | |
204 | - | then $acc256715714 | |
205 | - | else { | |
206 | - | let $acc356715714 = getStepAmount($acc256715714, $list56715714[2]) | |
207 | - | if (($size56715714 == 3)) | |
208 | - | then $acc356715714 | |
209 | - | else { | |
210 | - | let $acc456715714 = getStepAmount($acc356715714, $list56715714[3]) | |
211 | - | if (($size56715714 == 4)) | |
212 | - | then $acc456715714 | |
213 | - | else { | |
214 | - | let $acc556715714 = getStepAmount($acc456715714, $list56715714[4]) | |
215 | - | if (($size56715714 == 5)) | |
216 | - | then $acc556715714 | |
217 | - | else { | |
218 | - | let $acc656715714 = getStepAmount($acc556715714, $list56715714[5]) | |
219 | - | throw("List size exceed 5") | |
220 | - | } | |
221 | - | } | |
222 | - | } | |
223 | - | } | |
224 | - | } | |
225 | - | } | |
226 | - | } | |
227 | - | if ((0 > stepAmount)) | |
228 | - | then throw("something went wrong while working with amountToSend") | |
229 | - | else if (if ((invariantEstimatedRatio > slippageValue)) | |
230 | - | then (invariantNew > invariant) | |
231 | - | else false) | |
232 | - | then amountToSendEstimated | |
233 | - | else stepAmount | |
234 | - | } | |
235 | - | ||
236 | - | ||
237 | 139 | func getAssetInfo (assetId) = match assetId { | |
238 | 140 | case id: ByteVector => | |
239 | 141 | let stringId = toBase58String(id) | |
246 | 148 | } | |
247 | 149 | ||
248 | 150 | ||
249 | - | func suspend (cause) = [BooleanEntry( | |
151 | + | func suspend (cause) = [BooleanEntry(keyActive, false), StringEntry(keyCause, cause)] | |
250 | 152 | ||
251 | 153 | ||
252 | 154 | func deductStakingFee (amount,assetId) = if ((assetId == USDN)) | |
259 | 161 | else amount | |
260 | 162 | ||
261 | 163 | ||
262 | - | func throwIsActive () = throw("DApp is already active") | |
263 | - | ||
264 | - | ||
265 | - | func throwIsInactive () = throw("DApp is inactive at this moment") | |
266 | - | ||
267 | - | ||
268 | - | func throwOnlyAdmin () = throw("Only admin can call this function") | |
269 | - | ||
270 | - | ||
271 | - | func throwAssets () = throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
272 | - | ||
273 | - | ||
274 | - | func throwThreshold (threshold,amountA,amountB) = throw(((((((((("New balance in assets of the DApp is less than threshold " + toString(threshold)) + ": ") + toString(amountA)) + " ") + assetNameA) + ", ") + toString(amountB)) + " ") + assetNameB)) | |
275 | - | ||
276 | - | ||
277 | 164 | func throwInsufficientAvailableBalance (amount,available,assetName) = throw((((((((("Insufficient DApp balance to pay " + toString(amount)) + " ") + assetName) + " due to staking. Available: ") + toString(available)) + " ") + assetName) + ". Please contact support in Telegram: https://t.me/swopfisupport")) | |
278 | 165 | ||
279 | 166 | ||
280 | 167 | func throwInsufficientAvailableBalances (amountA,amountB) = throw((((((((((((((((("Insufficient DApp balance to pay " + toString(amountA)) + " ") + assetNameA) + " and ") + toString(amountB)) + " ") + assetNameB) + " due to staking. Available: ") + toString(availableBalanceA)) + " ") + assetNameA) + " and ") + toString(availableBalanceB)) + " ") + assetNameB) + ". Please contact support in Telegram: https://t.me/swopfisupport")) | |
281 | 168 | ||
282 | 169 | ||
283 | - | func suspendSuspicious () = suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
284 | - | ||
285 | - | ||
286 | 170 | @Callable(i) | |
287 | 171 | func init () = { | |
288 | - | let $ | |
289 | - | let pmtAmountA = $ | |
290 | - | let pmtAssetIdA = $ | |
291 | - | let $ | |
292 | - | let pmtAmountB = $ | |
293 | - | let pmtAssetIdB = $ | |
294 | - | let $ | |
295 | - | let pmtStrAssetIdA = $ | |
296 | - | let pmtAssetNameA = $ | |
297 | - | let pmtDecimalsA = $ | |
298 | - | let $ | |
299 | - | let pmtStrAssetIdB = $ | |
300 | - | let pmtAssetNameB = $ | |
301 | - | let pmtDecimalsB = $ | |
302 | - | if (isDefined(getBoolean(this, | |
303 | - | then | |
172 | + | let $t047504827 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
173 | + | let pmtAmountA = $t047504827._1 | |
174 | + | let pmtAssetIdA = $t047504827._2 | |
175 | + | let $t048324909 = $Tuple2(i.payments[1].amount, i.payments[1].assetId) | |
176 | + | let pmtAmountB = $t048324909._1 | |
177 | + | let pmtAssetIdB = $t048324909._2 | |
178 | + | let $t049144991 = getAssetInfo(pmtAssetIdA) | |
179 | + | let pmtStrAssetIdA = $t049144991._1 | |
180 | + | let pmtAssetNameA = $t049144991._2 | |
181 | + | let pmtDecimalsA = $t049144991._3 | |
182 | + | let $t049965073 = getAssetInfo(pmtAssetIdB) | |
183 | + | let pmtStrAssetIdB = $t049965073._1 | |
184 | + | let pmtAssetNameB = $t049965073._2 | |
185 | + | let pmtDecimalsB = $t049965073._3 | |
186 | + | if (isDefined(getBoolean(this, keyActive))) | |
187 | + | then throw("DApp is already active") | |
304 | 188 | else if ((pmtAssetIdA == pmtAssetIdB)) | |
305 | 189 | then throw("Assets must be different") | |
306 | 190 | else { | |
310 | 194 | let shareInitialSupply = fraction(pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, HALFDOWN), pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, HALFDOWN), pow(10, 0, shareDecimals, 0, 0, HALFDOWN)) | |
311 | 195 | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
312 | 196 | let shareIssueId = calculateAssetId(shareIssue) | |
313 | - | let invariantCalculated = invariantCalc(pmtAmountA, pmtAmountB) | |
314 | - | [StringEntry(kVersion, version), BooleanEntry(kActive, true), StringEntry(kAssetIdA, pmtStrAssetIdA), StringEntry(kAssetIdB, pmtStrAssetIdB), IntegerEntry(kBalanceA, pmtAmountA), IntegerEntry(kBalanceB, pmtAmountB), IntegerEntry(kInvariant, invariantCalculated), IntegerEntry(kFee, fee), IntegerEntry(kFeeScaleDelimiter, feeScale6), shareIssue, StringEntry(kShareAssetId, toBase58String(shareIssueId)), IntegerEntry(kShareAssetSupply, shareInitialSupply), ScriptTransfer(i.caller, shareInitialSupply, shareIssueId)] | |
197 | + | [StringEntry(keyVersion, version), BooleanEntry(keyActive, true), StringEntry(keyAssetIdA, pmtStrAssetIdA), StringEntry(keyAssetIdB, pmtStrAssetIdB), IntegerEntry(keyBalanceA, pmtAmountA), IntegerEntry(keyBalanceB, pmtAmountB), IntegerEntry(keyCommission, commission), IntegerEntry(keyCommissionScaleDelimiter, commissionScaleDelimiter), shareIssue, StringEntry(keyShareAssetId, toBase58String(shareIssueId)), IntegerEntry(keyShareAssetSupply, shareInitialSupply), ScriptTransfer(i.caller, shareInitialSupply, shareIssueId)] | |
315 | 198 | } | |
316 | 199 | } | |
317 | 200 | ||
323 | 206 | let pmtAssetIdB = i.payments[1].assetId | |
324 | 207 | let pmtAmountA = deductStakingFee(i.payments[0].amount, pmtAssetIdA) | |
325 | 208 | let pmtAmountB = deductStakingFee(i.payments[1].amount, pmtAssetIdB) | |
326 | - | let tokenRatio = fraction(fraction(scale8, balanceA, pmtAmountA), scale3, fraction(scale8, balanceB, pmtAmountB)) | |
327 | - | let ratioShareTokensInA = fraction(scale8, pmtAmountA, balanceA) | |
328 | - | let ratioShareTokensInB = fraction(scale8, pmtAmountB, balanceB) | |
329 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
330 | - | let invariantCalculated = invariantCalc((balanceA + pmtAmountA), (balanceB + pmtAmountB)) | |
209 | + | let tokenRatio = fraction(fraction(balanceA, scaleValue8, pmtAmountA), scaleValue3, fraction(balanceB, scaleValue8, pmtAmountB)) | |
210 | + | let ratioShareTokensInA = fraction(pmtAmountA, scaleValue8, balanceA) | |
211 | + | let ratioShareTokensInB = fraction(pmtAmountB, scaleValue8, balanceB) | |
212 | + | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scaleValue8) | |
331 | 213 | if (!(isActive)) | |
332 | - | then | |
214 | + | then throw("DApp is inactive at this moment") | |
333 | 215 | else if (if ((0 > slippageTolerance)) | |
334 | 216 | then true | |
335 | - | else (slippageTolerance > | |
336 | - | then throw("Slippage tolerance must be | |
217 | + | else (slippageTolerance > slippageToleranceDelimiter)) | |
218 | + | then throw(((("Slippage tolerance must be between 0 and " + toString(slippageToleranceDelimiter)) + " inclusively. Actual: ") + toString(slippageTolerance))) | |
337 | 219 | else if ((size(i.payments) != 2)) | |
338 | 220 | then throw("Two attached assets expected") | |
339 | 221 | else if (if ((pmtAssetIdA != assetIdA)) | |
340 | 222 | then true | |
341 | 223 | else (pmtAssetIdB != assetIdB)) | |
342 | - | then | |
343 | - | else if (if (((( | |
224 | + | then throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
225 | + | else if (if ((((scaleValue3 * (slippageToleranceDelimiter - slippageTolerance)) / slippageToleranceDelimiter) > tokenRatio)) | |
344 | 226 | then true | |
345 | - | else (tokenRatio > (( | |
227 | + | else (tokenRatio > ((scaleValue3 * (slippageToleranceDelimiter + slippageTolerance)) / slippageToleranceDelimiter))) | |
346 | 228 | then throw("Incorrect assets amount: amounts must have the contract ratio") | |
347 | 229 | else if ((shareTokenToPayAmount == 0)) | |
348 | 230 | then throw("Too small amount to replenish") | |
349 | 231 | else if (!(hasEnoughBalance)) | |
350 | - | then suspendSuspicious() | |
351 | - | else [IntegerEntry(kBalanceA, (balanceA + pmtAmountA)), IntegerEntry(kBalanceB, (balanceB + pmtAmountB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), IntegerEntry(kInvariant, invariantCalculated), Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId)] | |
352 | - | } | |
353 | - | ||
354 | - | ||
355 | - | ||
356 | - | @Callable(i) | |
357 | - | func replenishWithOneToken (virtualSwapTokenPay,virtualSwapTokenGet) = { | |
358 | - | let $t01293213007 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
359 | - | let pmtAmount = $t01293213007._1 | |
360 | - | let pmtAssetId = $t01293213007._2 | |
361 | - | let pmtMinThreshold = 5000000 | |
362 | - | let thresholdValueForMinTolerance = 50000000 | |
363 | - | let tolerance = if ((thresholdValueForMinTolerance > pmtAmount)) | |
364 | - | then 100000 | |
365 | - | else 1 | |
366 | - | let slippageValueMinForReplenish = (scale8 - ((scale8 * tolerance) / 10000000)) | |
367 | - | let slippageValueMaxForReplenish = (scale8 + ((scale8 * tolerance) / 10000000)) | |
368 | - | let slippageValueMinForSwap = (scale8 - ((scale8 * 1) / 10000000)) | |
369 | - | let slippageValueMaxForSwap = (scale8 + ((scale8 * 1) / 10000000)) | |
370 | - | if (!(isActive)) | |
371 | - | then throwIsInactive() | |
372 | - | else if ((pmtMinThreshold > pmtAmount)) | |
373 | - | then throw((((("Payment amount " + toString(pmtAmount)) + " does not exceed the minimum amount of ") + toString(pmtMinThreshold)) + " tokens")) | |
374 | - | else if ((size(i.payments) != 1)) | |
375 | - | then throw("One attached payment expected") | |
376 | - | else if (!(hasEnoughBalance)) | |
377 | - | then suspendSuspicious() | |
378 | - | else if (if ((pmtAssetId != assetIdA)) | |
379 | - | then (pmtAssetId != assetIdB) | |
380 | - | else false) | |
381 | - | then throwAssets() | |
382 | - | else { | |
383 | - | let $t01400914774 = if ((pmtAssetId == assetIdA)) | |
384 | - | then $Tuple7((pmtAmount - virtualSwapTokenPay), virtualSwapTokenGet, (balanceA + virtualSwapTokenPay), (balanceB - virtualSwapTokenGet), invariantCalc((balanceA + pmtAmount), balanceB), (balanceA + pmtAmount), balanceB) | |
385 | - | else $Tuple7(virtualSwapTokenGet, (pmtAmount - virtualSwapTokenPay), (balanceA - virtualSwapTokenGet), (balanceB + virtualSwapTokenPay), invariantCalc(balanceA, (balanceB + pmtAmount)), balanceA, (balanceB + pmtAmount)) | |
386 | - | let virtualReplenishA = $t01400914774._1 | |
387 | - | let virtualReplenishB = $t01400914774._2 | |
388 | - | let balanceAfterSwapA = $t01400914774._3 | |
389 | - | let balanceAfterSwapB = $t01400914774._4 | |
390 | - | let invariantCalculated = $t01400914774._5 | |
391 | - | let newBalanceA = $t01400914774._6 | |
392 | - | let newBalanceB = $t01400914774._7 | |
393 | - | let newBalanceEntry = if ((pmtAssetId == assetIdA)) | |
394 | - | then IntegerEntry(kBalanceA, newBalanceA) | |
395 | - | else IntegerEntry(kBalanceB, newBalanceB) | |
396 | - | let invariantNew = invariantCalc(balanceAfterSwapA, balanceAfterSwapB) | |
397 | - | let invariantEstimatedRatio = fraction(scale8, invariant, invariantNew) | |
398 | - | let ratioVirtualBalanceToVirtualReplenish = (fraction((scale8 * scale8), balanceAfterSwapA, balanceAfterSwapB) / fraction(scale8, virtualReplenishA, virtualReplenishB)) | |
399 | - | let dAppThresholdAmount = fraction((newBalanceA + newBalanceB), dAppThreshold, (2 * dAppThresholdScale2)) | |
400 | - | if (if ((slippageValueMinForSwap >= invariantEstimatedRatio)) | |
401 | - | then true | |
402 | - | else (invariant > invariantNew)) | |
403 | - | then throw("Incorrect virtualSwapTokenPay or virtualSwapTokenGet value") | |
404 | - | else if (if ((slippageValueMinForReplenish > ratioVirtualBalanceToVirtualReplenish)) | |
405 | - | then true | |
406 | - | else (ratioVirtualBalanceToVirtualReplenish > slippageValueMaxForReplenish)) | |
407 | - | then throw("Swap with virtualSwapTokenPay and virtualSwapTokenGet is possible, but ratio after virtual swap is incorrect") | |
408 | - | else if (if ((dAppThresholdAmount > newBalanceA)) | |
409 | - | then true | |
410 | - | else (dAppThresholdAmount > newBalanceB)) | |
411 | - | then throwThreshold(dAppThresholdAmount, newBalanceA, newBalanceB) | |
412 | - | else { | |
413 | - | let ratioShareTokensInA = fraction(deductStakingFee(virtualReplenishA, assetIdA), scale8, balanceAfterSwapA) | |
414 | - | let ratioShareTokensInB = fraction(deductStakingFee(virtualReplenishB, assetIdB), scale8, balanceAfterSwapB) | |
415 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
416 | - | [Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), newBalanceEntry, IntegerEntry(kInvariant, invariantCalculated)] | |
417 | - | } | |
418 | - | } | |
232 | + | then suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
233 | + | else [IntegerEntry(keyBalanceA, (balanceA + pmtAmountA)), IntegerEntry(keyBalanceB, (balanceB + pmtAmountB)), IntegerEntry(keyShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId)] | |
419 | 234 | } | |
420 | 235 | ||
421 | 236 | ||
422 | 237 | ||
423 | 238 | @Callable(i) | |
424 | 239 | func withdraw () = { | |
425 | - | let $ | |
426 | - | let pmtAmount = $ | |
427 | - | let pmtAssetId = $ | |
240 | + | let $t092679417 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
241 | + | let pmtAmount = $t092679417._1 | |
242 | + | let pmtAssetId = $t092679417._2 | |
428 | 243 | let amountToPayA = deductStakingFee(fraction(pmtAmount, balanceA, shareAssetSupply), assetIdA) | |
429 | 244 | let amountToPayB = deductStakingFee(fraction(pmtAmount, balanceB, shareAssetSupply), assetIdB) | |
430 | - | let invariantCalculated = invariantCalc((balanceA - amountToPayA), (balanceB - amountToPayB)) | |
431 | 245 | if (!(isActive)) | |
432 | - | then | |
246 | + | then throw("DApp is inactive at this moment") | |
433 | 247 | else if ((size(i.payments) != 1)) | |
434 | 248 | then throw("One attached payment expected") | |
435 | 249 | else if ((pmtAssetId != shareAssetId)) | |
436 | 250 | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
437 | 251 | else if (!(hasEnoughBalance)) | |
438 | - | then | |
252 | + | then suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
439 | 253 | else if (if ((amountToPayA > availableBalanceA)) | |
440 | 254 | then true | |
441 | 255 | else (amountToPayB > availableBalanceB)) | |
442 | 256 | then throwInsufficientAvailableBalances(amountToPayA, amountToPayB) | |
443 | - | else [IntegerEntry( | |
257 | + | else [IntegerEntry(keyBalanceA, (balanceA - amountToPayA)), IntegerEntry(keyBalanceB, (balanceB - amountToPayB)), IntegerEntry(keyShareAssetSupply, (shareAssetSupply - pmtAmount)), Burn(shareAssetId, pmtAmount), ScriptTransfer(i.caller, amountToPayA, assetIdA), ScriptTransfer(i.caller, amountToPayB, assetIdB)] | |
444 | 258 | } | |
445 | 259 | ||
446 | 260 | ||
447 | 261 | ||
448 | 262 | @Callable(i) | |
449 | - | func exchange (estimatedAmountToReceive,minAmountToReceive) = { | |
450 | - | let $t01835318428 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
451 | - | let pmtAmount = $t01835318428._1 | |
452 | - | let pmtAssetId = $t01835318428._2 | |
263 | + | func exchange (minAmountToReceive) = { | |
264 | + | let $t01080710882 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
265 | + | let pmtAmount = $t01080710882._1 | |
266 | + | let pmtAssetId = $t01080710882._2 | |
267 | + | func calculateFees (tokenFrom,tokenTo) = { | |
268 | + | let amountWithoutFee = fraction(tokenTo, pmtAmount, (pmtAmount + tokenFrom)) | |
269 | + | let amountWithFee = fraction(amountWithoutFee, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
270 | + | let governanceReward = fraction(amountWithoutFee, commissionGovernance, commissionScaleDelimiter) | |
271 | + | if ((minAmountToReceive > amountWithFee)) | |
272 | + | then throw(((("Calculated amount to receive " + toString(amountWithFee)) + " is less than specified minimum ") + toString(minAmountToReceive))) | |
273 | + | else $Tuple3(amountWithoutFee, amountWithFee, governanceReward) | |
274 | + | } | |
275 | + | ||
453 | 276 | if (!(isActive)) | |
454 | - | then throwIsInactive() | |
455 | - | else if ((0 >= estimatedAmountToReceive)) | |
456 | - | then throw(("Estimated amount must be positive. Actual: " + toString(estimatedAmountToReceive))) | |
457 | - | else if ((minAmountToReceive > estimatedAmountToReceive)) | |
458 | - | then throw(((("Minimal amount can't be greater than estimated. Estimated: " + toString(estimatedAmountToReceive)) + ". Minimal: ") + toString(minAmountToReceive))) | |
459 | - | else if ((size(i.payments) != 1)) | |
460 | - | then throw("One attached payment expected") | |
461 | - | else if (!(hasEnoughBalance)) | |
462 | - | then suspendSuspicious() | |
463 | - | else if (if ((pmtAssetId != assetIdA)) | |
464 | - | then (pmtAssetId != assetIdB) | |
465 | - | else false) | |
466 | - | then throwAssets() | |
467 | - | else if ((10000000 > pmtAmount)) | |
468 | - | then throw("Only swap of 10.000000 or more tokens is allowed") | |
469 | - | else if (if ((exchangeRatioLimitMin > fraction(scale8, minAmountToReceive, pmtAmount))) | |
277 | + | then throw("DApp is inactive at this moment") | |
278 | + | else if ((0 >= minAmountToReceive)) | |
279 | + | then throw(("Minimal amount to receive must be positive. Actual: " + toString(minAmountToReceive))) | |
280 | + | else if ((size(i.payments) != 1)) | |
281 | + | then throw("One attached payment expected") | |
282 | + | else if (!(hasEnoughBalance)) | |
283 | + | then suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
284 | + | else if ((pmtAssetId == assetIdA)) | |
285 | + | then { | |
286 | + | let assetIdSend = assetIdB | |
287 | + | let $t01224112332 = calculateFees(balanceA, balanceB) | |
288 | + | let amountWithoutFee = $t01224112332._1 | |
289 | + | let amountWithFee = $t01224112332._2 | |
290 | + | let governanceReward = $t01224112332._3 | |
291 | + | let newBalanceA = (balanceA + pmtAmount) | |
292 | + | let newBalanceB = ((balanceB - amountWithFee) - governanceReward) | |
293 | + | if (if (if ((assetIdA == USDN)) | |
294 | + | then (stakedAmountUSDN >= newBalanceA) | |
295 | + | else false) | |
296 | + | then true | |
297 | + | else if ((assetIdB == USDN)) | |
298 | + | then (stakedAmountUSDN >= newBalanceB) | |
299 | + | else false) | |
300 | + | then throwInsufficientAvailableBalance(amountWithFee, availableBalanceB, assetNameB) | |
301 | + | else [IntegerEntry(keyBalanceA, newBalanceA), IntegerEntry(keyBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(governanceAddress, governanceReward, assetIdSend)] | |
302 | + | } | |
303 | + | else if ((pmtAssetId == assetIdB)) | |
304 | + | then { | |
305 | + | let assetIdSend = assetIdA | |
306 | + | let $t01320513296 = calculateFees(balanceB, balanceA) | |
307 | + | let amountWithoutFee = $t01320513296._1 | |
308 | + | let amountWithFee = $t01320513296._2 | |
309 | + | let governanceReward = $t01320513296._3 | |
310 | + | let newBalanceA = ((balanceA - amountWithFee) - governanceReward) | |
311 | + | let newBalanceB = (balanceB + pmtAmount) | |
312 | + | if (if (if ((assetIdA == USDN)) | |
313 | + | then (stakedAmountUSDN >= newBalanceA) | |
314 | + | else false) | |
470 | 315 | then true | |
471 | - | else (fraction(scale8, estimatedAmountToReceive, pmtAmount) > exchangeRatioLimitMax)) | |
472 | - | then throw("Incorrect args and pmt ratio") | |
473 | - | else { | |
474 | - | let sendAssetId = if ((pmtAssetId == assetIdA)) | |
475 | - | then assetIdB | |
476 | - | else assetIdA | |
477 | - | let amount = calculateSendAmount(estimatedAmountToReceive, minAmountToReceive, pmtAmount, pmtAssetId) | |
478 | - | let governanceReward = fraction(amount, feeGovernance, feeScale6) | |
479 | - | let amountMinusFee = fraction(amount, (feeScale6 - fee), feeScale6) | |
480 | - | let $t01977920042 = if ((pmtAssetId == assetIdA)) | |
481 | - | then $Tuple2((balanceA + pmtAmount), ((balanceB - amountMinusFee) - governanceReward)) | |
482 | - | else $Tuple2(((balanceA - amountMinusFee) - governanceReward), (balanceB + pmtAmount)) | |
483 | - | let newBalanceA = $t01977920042._1 | |
484 | - | let newBalanceB = $t01977920042._2 | |
485 | - | let dAppThresholdAmount = fraction((newBalanceA + newBalanceB), dAppThreshold, (2 * dAppThresholdScale2)) | |
486 | - | if (if ((dAppThresholdAmount > newBalanceA)) | |
487 | - | then true | |
488 | - | else (dAppThresholdAmount > newBalanceB)) | |
489 | - | then throwThreshold(dAppThresholdAmount, newBalanceA, newBalanceB) | |
490 | - | else if (if (if ((assetIdA == USDN)) | |
491 | - | then (sendAssetId == assetIdA) | |
492 | - | else false) | |
493 | - | then (stakedAmountUSDN >= newBalanceA) | |
494 | - | else false) | |
495 | - | then throwInsufficientAvailableBalance(amountMinusFee, availableBalanceA, assetNameA) | |
496 | - | else if (if (if ((assetIdB == USDN)) | |
497 | - | then (sendAssetId == assetIdB) | |
498 | - | else false) | |
499 | - | then (stakedAmountUSDN >= newBalanceB) | |
500 | - | else false) | |
501 | - | then throwInsufficientAvailableBalance(amountMinusFee, availableBalanceB, assetNameB) | |
502 | - | else [IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), IntegerEntry(kInvariant, invariantCalc(newBalanceA, newBalanceB)), ScriptTransfer(i.caller, amountMinusFee, sendAssetId), ScriptTransfer(govAddr, governanceReward, sendAssetId)] | |
503 | - | } | |
316 | + | else if ((assetIdB == USDN)) | |
317 | + | then (stakedAmountUSDN >= newBalanceB) | |
318 | + | else false) | |
319 | + | then throwInsufficientAvailableBalance(amountWithFee, availableBalanceA, assetNameA) | |
320 | + | else [IntegerEntry(keyBalanceA, newBalanceA), IntegerEntry(keyBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(governanceAddress, governanceReward, assetIdSend)] | |
321 | + | } | |
322 | + | else throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
504 | 323 | } | |
505 | 324 | ||
506 | 325 | ||
507 | 326 | ||
508 | 327 | @Callable(i) | |
509 | 328 | func shutdown () = if (!(isActive)) | |
510 | - | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, | |
511 | - | else if (!(containsElement([ | |
512 | - | then | |
329 | + | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, keyCause), "the cause wasn't specified"))) | |
330 | + | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminPubKeyStartStop], i.callerPublicKey))) | |
331 | + | then throw("Only admin can call this function") | |
513 | 332 | else suspend("Paused by admin") | |
514 | 333 | ||
515 | 334 | ||
516 | 335 | ||
517 | 336 | @Callable(i) | |
518 | 337 | func activate () = if (isActive) | |
519 | - | then | |
520 | - | else if (!(containsElement([ | |
521 | - | then | |
522 | - | else [BooleanEntry( | |
338 | + | then throw("DApp is already active") | |
339 | + | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminPubKeyStartStop], i.callerPublicKey))) | |
340 | + | then throw("Only admin can call this function") | |
341 | + | else [BooleanEntry(keyActive, true), DeleteEntry(keyCause)] | |
523 | 342 | ||
524 | 343 | ||
525 | 344 | ||
526 | 345 | @Callable(i) | |
527 | 346 | func takeIntoAccountExtraFunds (amountLeave) = { | |
528 | - | let | |
529 | - | let | |
530 | - | let amountEnrollA = ( | |
347 | + | let uncountableAmountEnrollAssetA = (accountBalanceWithStakedA - balanceA) | |
348 | + | let uncountableAmountEnrollAssetB = (accountBalanceWithStakedB - balanceB) | |
349 | + | let amountEnrollA = (uncountableAmountEnrollAssetA - (if ((assetIdA == USDN)) | |
531 | 350 | then amountLeave | |
532 | 351 | else 0)) | |
533 | - | let amountEnrollB = ( | |
352 | + | let amountEnrollB = (uncountableAmountEnrollAssetB - (if ((assetIdB == USDN)) | |
534 | 353 | then amountLeave | |
535 | 354 | else 0)) | |
536 | 355 | if (!(isActive)) | |
537 | - | then | |
356 | + | then throw("DApp is inactive at this moment") | |
538 | 357 | else if ((i.caller != this)) | |
539 | - | then | |
358 | + | then throw("Only the DApp itself can call this function") | |
540 | 359 | else if ((0 > amountLeave)) | |
541 | 360 | then throw(("Argument 'amountLeave' cannot be negative. Actual: " + toString(amountLeave))) | |
542 | - | else if (if ((0 > | |
361 | + | else if (if ((0 > uncountableAmountEnrollAssetA)) | |
543 | 362 | then true | |
544 | - | else (0 > | |
363 | + | else (0 > uncountableAmountEnrollAssetB)) | |
545 | 364 | then suspend("Enroll amount negative") | |
546 | 365 | else if (if ((0 > amountEnrollA)) | |
547 | 366 | then true | |
548 | 367 | else (0 > amountEnrollB)) | |
549 | 368 | then throw("Too large amountLeave") | |
550 | - | else [IntegerEntry( | |
369 | + | else [IntegerEntry(keyBalanceA, (balanceA + amountEnrollA)), IntegerEntry(keyBalanceB, (balanceB + amountEnrollB)), IntegerEntry(("last_income_" + strAssetIdA), amountEnrollA), IntegerEntry(("last_income_" + strAssetIdB), amountEnrollB)] | |
551 | 370 | } | |
552 | 371 | ||
553 | 372 | ||
568 | 387 | then (size(invoke.payments) == 0) | |
569 | 388 | else false | |
570 | 389 | else false | |
571 | - | let signedByAdmin = if (if (if (sigVerify(tx.bodyBytes, tx.proofs[0], | |
390 | + | let signedByAdmin = if (if (if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
572 | 391 | then true | |
573 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], | |
392 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey2)) | |
574 | 393 | then true | |
575 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], | |
394 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey3)) | |
576 | 395 | then true | |
577 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], | |
396 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKeyStaking) | |
578 | 397 | if (callTakeIntoAccount) | |
579 | 398 | then true | |
580 | 399 | else callStaking |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let version = " | |
4 | + | let version = "1.0.0" | |
5 | 5 | ||
6 | - | let | |
6 | + | let keyVersion = "version" | |
7 | 7 | ||
8 | - | let | |
8 | + | let keyActive = "active" | |
9 | 9 | ||
10 | - | let | |
10 | + | let keyAssetIdA = "A_asset_id" | |
11 | 11 | ||
12 | - | let | |
12 | + | let keyAssetIdB = "B_asset_id" | |
13 | 13 | ||
14 | - | let | |
14 | + | let keyBalanceA = "A_asset_balance" | |
15 | 15 | ||
16 | - | let | |
16 | + | let keyBalanceB = "B_asset_balance" | |
17 | 17 | ||
18 | - | let | |
18 | + | let keyShareAssetId = "share_asset_id" | |
19 | 19 | ||
20 | - | let | |
20 | + | let keyShareAssetSupply = "share_asset_supply" | |
21 | 21 | ||
22 | - | let | |
22 | + | let keyCommission = "commission" | |
23 | 23 | ||
24 | - | let | |
24 | + | let keyCommissionScaleDelimiter = "commission_scale_delimiter" | |
25 | 25 | ||
26 | - | let | |
26 | + | let keyCause = "shutdown_cause" | |
27 | 27 | ||
28 | - | let | |
28 | + | let adminPubKey1 = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
29 | 29 | ||
30 | - | let | |
30 | + | let adminPubKey2 = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
31 | 31 | ||
32 | - | let | |
32 | + | let adminPubKey3 = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
33 | 33 | ||
34 | - | let | |
34 | + | let adminPubKeyStartStop = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
35 | 35 | ||
36 | - | let | |
36 | + | let adminPubKeyStaking = base58'Kn7NpzaG12dLZgcHf2ipUftU6hbJygmrhFqQYE4B7ZK' | |
37 | 37 | ||
38 | - | let | |
38 | + | let governanceAddress = Address(base58'3NAGTtZz6WpupSN89NZD5rMZwwziZEg4Kx4') | |
39 | 39 | ||
40 | - | let govAddr = Address(base58'3NAGTtZz6WpupSN89NZD5rMZwwziZEg4Kx4') | |
41 | - | ||
42 | - | let stakingAddress = Address(base58'3ND2G6RdHNnSNUzyPsWhQ6L7pEUUAyfrWzo') | |
40 | + | let stakingAddress = Address(base58'3N6q7sCGSSLBUXDdjBdYGTJbZGZfhhh8cNg') | |
43 | 41 | ||
44 | 42 | let USDN = base58'8UrfDVd5GreeUwm7uPk7eYz1eMv376kzR52C6sANPkwS' | |
45 | 43 | ||
46 | 44 | let stakingFeeInUSDN = (9 * value(value(assetInfo(USDN)).minSponsoredFee)) | |
47 | 45 | ||
48 | - | let isActive = getBooleanValue(this, | |
46 | + | let isActive = getBooleanValue(this, keyActive) | |
49 | 47 | ||
50 | - | let strAssetIdA = getStringValue(this, | |
48 | + | let strAssetIdA = getStringValue(this, keyAssetIdA) | |
51 | 49 | ||
52 | - | let strAssetIdB = getStringValue(this, | |
50 | + | let strAssetIdB = getStringValue(this, keyAssetIdB) | |
53 | 51 | ||
54 | 52 | let assetIdA = if ((strAssetIdA == "WAVES")) | |
55 | 53 | then unit | |
56 | 54 | else fromBase58String(strAssetIdA) | |
57 | 55 | ||
58 | 56 | let assetIdB = if ((strAssetIdB == "WAVES")) | |
59 | 57 | then unit | |
60 | 58 | else fromBase58String(strAssetIdB) | |
61 | 59 | ||
62 | 60 | let assetNameA = match assetIdA { | |
63 | 61 | case id: ByteVector => | |
64 | 62 | value(assetInfo(id)).name | |
65 | 63 | case waves: Unit => | |
66 | 64 | "WAVES" | |
67 | 65 | case _ => | |
68 | 66 | throw("Match error") | |
69 | 67 | } | |
70 | 68 | ||
71 | 69 | let assetNameB = match assetIdB { | |
72 | 70 | case id: ByteVector => | |
73 | 71 | value(assetInfo(id)).name | |
74 | 72 | case waves: Unit => | |
75 | 73 | "WAVES" | |
76 | 74 | case _ => | |
77 | 75 | throw("Match error") | |
78 | 76 | } | |
79 | 77 | ||
80 | - | let balanceA = getIntegerValue(this, | |
78 | + | let balanceA = getIntegerValue(this, keyBalanceA) | |
81 | 79 | ||
82 | - | let balanceB = getIntegerValue(this, | |
80 | + | let balanceB = getIntegerValue(this, keyBalanceB) | |
83 | 81 | ||
84 | - | let shareAssetId = fromBase58String(getStringValue(this, | |
82 | + | let shareAssetId = fromBase58String(getStringValue(this, keyShareAssetId)) | |
85 | 83 | ||
86 | - | let shareAssetSupply = getIntegerValue(this, | |
84 | + | let shareAssetSupply = getIntegerValue(this, keyShareAssetSupply) | |
87 | 85 | ||
88 | - | let | |
86 | + | let commission = 3000 | |
89 | 87 | ||
90 | - | let | |
88 | + | let commissionGovernance = 1200 | |
91 | 89 | ||
92 | - | let | |
90 | + | let commissionScaleDelimiter = 1000000 | |
93 | 91 | ||
94 | - | let | |
92 | + | let scaleValue3 = 1000 | |
95 | 93 | ||
96 | - | let | |
94 | + | let scaleValue8 = 100000000 | |
97 | 95 | ||
98 | - | let | |
96 | + | let slippageToleranceDelimiter = 1000 | |
99 | 97 | ||
100 | - | let scale12 = 1000000000000 | |
101 | - | ||
102 | - | let slippageScale3 = 1000 | |
103 | - | ||
104 | - | let digits8 = 8 | |
105 | - | ||
106 | - | let dAppThreshold = 50 | |
107 | - | ||
108 | - | let dAppThresholdScale2 = 100 | |
109 | - | ||
110 | - | let exchangeRatioLimitMin = 90000000 | |
111 | - | ||
112 | - | let exchangeRatioLimitMax = 110000000 | |
113 | - | ||
114 | - | let alpha = 50 | |
115 | - | ||
116 | - | let alphaDigits = 2 | |
117 | - | ||
118 | - | let beta = 46000000 | |
98 | + | let scaleValue8Digits = 8 | |
119 | 99 | ||
120 | 100 | func accountBalance (assetId) = match assetId { | |
121 | 101 | case id: ByteVector => | |
122 | 102 | assetBalance(this, id) | |
123 | 103 | case waves: Unit => | |
124 | 104 | wavesBalance(this).available | |
125 | 105 | case _ => | |
126 | 106 | throw("Match error") | |
127 | 107 | } | |
128 | 108 | ||
129 | 109 | ||
130 | 110 | let stakedAmountUSDN = match getInteger(stakingAddress, ((("rpd_balance_" + toBase58String(USDN)) + "_") + toString(this))) { | |
131 | 111 | case staked: Int => | |
132 | 112 | staked | |
133 | 113 | case nothing: Unit => | |
134 | 114 | 0 | |
135 | 115 | case _ => | |
136 | 116 | throw("Match error") | |
137 | 117 | } | |
138 | 118 | ||
139 | 119 | let availableBalanceA = (balanceA - (if ((assetIdA == USDN)) | |
140 | 120 | then stakedAmountUSDN | |
141 | 121 | else 0)) | |
142 | 122 | ||
143 | 123 | let availableBalanceB = (balanceB - (if ((assetIdB == USDN)) | |
144 | 124 | then stakedAmountUSDN | |
145 | 125 | else 0)) | |
146 | 126 | ||
147 | 127 | let accountBalanceWithStakedA = (accountBalance(assetIdA) + (if ((assetIdA == USDN)) | |
148 | 128 | then stakedAmountUSDN | |
149 | 129 | else 0)) | |
150 | 130 | ||
151 | 131 | let accountBalanceWithStakedB = (accountBalance(assetIdB) + (if ((assetIdB == USDN)) | |
152 | 132 | then stakedAmountUSDN | |
153 | 133 | else 0)) | |
154 | 134 | ||
155 | 135 | let hasEnoughBalance = if ((accountBalanceWithStakedA >= balanceA)) | |
156 | 136 | then (accountBalanceWithStakedB >= balanceB) | |
157 | 137 | else false | |
158 | 138 | ||
159 | - | func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000) | |
160 | - | ||
161 | - | ||
162 | - | func invariantCalc (x,y) = { | |
163 | - | let sk = skewness(x, y) | |
164 | - | (fraction((x + y), scale8, pow(sk, digits8, alpha, alphaDigits, digits8, UP)) + (2 * fraction(pow(fraction(x, y, scale8), 0, 5, 1, (digits8 / 2), DOWN), pow((sk - beta), digits8, alpha, alphaDigits, digits8, DOWN), scale8))) | |
165 | - | } | |
166 | - | ||
167 | - | ||
168 | - | func calculateSendAmount (amountToSendEstimated,minTokenReceiveAmount,tokenReceiveAmount,tokenId) = { | |
169 | - | let slippageValue = (scale8 - ((scale8 * 1) / 10000000)) | |
170 | - | let deltaBetweenMaxAndMinSendValue = (amountToSendEstimated - minTokenReceiveAmount) | |
171 | - | let x = (balanceA + tokenReceiveAmount) | |
172 | - | let y = (balanceB + tokenReceiveAmount) | |
173 | - | let invariantNew = if ((tokenId == assetIdA)) | |
174 | - | then invariantCalc(x, (balanceB - amountToSendEstimated)) | |
175 | - | else if ((tokenId == assetIdB)) | |
176 | - | then invariantCalc((balanceA - amountToSendEstimated), y) | |
177 | - | else throw("Wrong asset in payment") | |
178 | - | let invariantEstimatedRatio = fraction(scale8, invariant, invariantNew) | |
179 | - | func getStepAmount (acc,step) = if ((acc == -1)) | |
180 | - | then { | |
181 | - | let amountToSend = (amountToSendEstimated - ((step * deltaBetweenMaxAndMinSendValue) / 5)) | |
182 | - | let stepInvariant = if ((tokenId == assetIdA)) | |
183 | - | then invariantCalc(x, (balanceB - amountToSend)) | |
184 | - | else invariantCalc((balanceA - amountToSend), y) | |
185 | - | if ((stepInvariant > invariant)) | |
186 | - | then amountToSend | |
187 | - | else -1 | |
188 | - | } | |
189 | - | else acc | |
190 | - | ||
191 | - | let stepAmount = { | |
192 | - | let $list56715714 = [1, 2, 3, 4, 5] | |
193 | - | let $size56715714 = size($list56715714) | |
194 | - | let $acc056715714 = -1 | |
195 | - | if (($size56715714 == 0)) | |
196 | - | then $acc056715714 | |
197 | - | else { | |
198 | - | let $acc156715714 = getStepAmount($acc056715714, $list56715714[0]) | |
199 | - | if (($size56715714 == 1)) | |
200 | - | then $acc156715714 | |
201 | - | else { | |
202 | - | let $acc256715714 = getStepAmount($acc156715714, $list56715714[1]) | |
203 | - | if (($size56715714 == 2)) | |
204 | - | then $acc256715714 | |
205 | - | else { | |
206 | - | let $acc356715714 = getStepAmount($acc256715714, $list56715714[2]) | |
207 | - | if (($size56715714 == 3)) | |
208 | - | then $acc356715714 | |
209 | - | else { | |
210 | - | let $acc456715714 = getStepAmount($acc356715714, $list56715714[3]) | |
211 | - | if (($size56715714 == 4)) | |
212 | - | then $acc456715714 | |
213 | - | else { | |
214 | - | let $acc556715714 = getStepAmount($acc456715714, $list56715714[4]) | |
215 | - | if (($size56715714 == 5)) | |
216 | - | then $acc556715714 | |
217 | - | else { | |
218 | - | let $acc656715714 = getStepAmount($acc556715714, $list56715714[5]) | |
219 | - | throw("List size exceed 5") | |
220 | - | } | |
221 | - | } | |
222 | - | } | |
223 | - | } | |
224 | - | } | |
225 | - | } | |
226 | - | } | |
227 | - | if ((0 > stepAmount)) | |
228 | - | then throw("something went wrong while working with amountToSend") | |
229 | - | else if (if ((invariantEstimatedRatio > slippageValue)) | |
230 | - | then (invariantNew > invariant) | |
231 | - | else false) | |
232 | - | then amountToSendEstimated | |
233 | - | else stepAmount | |
234 | - | } | |
235 | - | ||
236 | - | ||
237 | 139 | func getAssetInfo (assetId) = match assetId { | |
238 | 140 | case id: ByteVector => | |
239 | 141 | let stringId = toBase58String(id) | |
240 | 142 | let info = valueOrErrorMessage(assetInfo(id), (("Asset " + stringId) + " doesn't exist")) | |
241 | 143 | $Tuple3(stringId, info.name, info.decimals) | |
242 | 144 | case waves: Unit => | |
243 | 145 | $Tuple3("WAVES", "WAVES", 8) | |
244 | 146 | case _ => | |
245 | 147 | throw("Match error") | |
246 | 148 | } | |
247 | 149 | ||
248 | 150 | ||
249 | - | func suspend (cause) = [BooleanEntry( | |
151 | + | func suspend (cause) = [BooleanEntry(keyActive, false), StringEntry(keyCause, cause)] | |
250 | 152 | ||
251 | 153 | ||
252 | 154 | func deductStakingFee (amount,assetId) = if ((assetId == USDN)) | |
253 | 155 | then { | |
254 | 156 | let result = (amount - stakingFeeInUSDN) | |
255 | 157 | if ((0 >= result)) | |
256 | 158 | then throw((((("Insufficient amount " + toString(amount)) + " to deduct staking fee ") + toString(stakingFeeInUSDN)) + " USD-N")) | |
257 | 159 | else result | |
258 | 160 | } | |
259 | 161 | else amount | |
260 | 162 | ||
261 | 163 | ||
262 | - | func throwIsActive () = throw("DApp is already active") | |
263 | - | ||
264 | - | ||
265 | - | func throwIsInactive () = throw("DApp is inactive at this moment") | |
266 | - | ||
267 | - | ||
268 | - | func throwOnlyAdmin () = throw("Only admin can call this function") | |
269 | - | ||
270 | - | ||
271 | - | func throwAssets () = throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
272 | - | ||
273 | - | ||
274 | - | func throwThreshold (threshold,amountA,amountB) = throw(((((((((("New balance in assets of the DApp is less than threshold " + toString(threshold)) + ": ") + toString(amountA)) + " ") + assetNameA) + ", ") + toString(amountB)) + " ") + assetNameB)) | |
275 | - | ||
276 | - | ||
277 | 164 | func throwInsufficientAvailableBalance (amount,available,assetName) = throw((((((((("Insufficient DApp balance to pay " + toString(amount)) + " ") + assetName) + " due to staking. Available: ") + toString(available)) + " ") + assetName) + ". Please contact support in Telegram: https://t.me/swopfisupport")) | |
278 | 165 | ||
279 | 166 | ||
280 | 167 | func throwInsufficientAvailableBalances (amountA,amountB) = throw((((((((((((((((("Insufficient DApp balance to pay " + toString(amountA)) + " ") + assetNameA) + " and ") + toString(amountB)) + " ") + assetNameB) + " due to staking. Available: ") + toString(availableBalanceA)) + " ") + assetNameA) + " and ") + toString(availableBalanceB)) + " ") + assetNameB) + ". Please contact support in Telegram: https://t.me/swopfisupport")) | |
281 | 168 | ||
282 | 169 | ||
283 | - | func suspendSuspicious () = suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
284 | - | ||
285 | - | ||
286 | 170 | @Callable(i) | |
287 | 171 | func init () = { | |
288 | - | let $ | |
289 | - | let pmtAmountA = $ | |
290 | - | let pmtAssetIdA = $ | |
291 | - | let $ | |
292 | - | let pmtAmountB = $ | |
293 | - | let pmtAssetIdB = $ | |
294 | - | let $ | |
295 | - | let pmtStrAssetIdA = $ | |
296 | - | let pmtAssetNameA = $ | |
297 | - | let pmtDecimalsA = $ | |
298 | - | let $ | |
299 | - | let pmtStrAssetIdB = $ | |
300 | - | let pmtAssetNameB = $ | |
301 | - | let pmtDecimalsB = $ | |
302 | - | if (isDefined(getBoolean(this, | |
303 | - | then | |
172 | + | let $t047504827 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
173 | + | let pmtAmountA = $t047504827._1 | |
174 | + | let pmtAssetIdA = $t047504827._2 | |
175 | + | let $t048324909 = $Tuple2(i.payments[1].amount, i.payments[1].assetId) | |
176 | + | let pmtAmountB = $t048324909._1 | |
177 | + | let pmtAssetIdB = $t048324909._2 | |
178 | + | let $t049144991 = getAssetInfo(pmtAssetIdA) | |
179 | + | let pmtStrAssetIdA = $t049144991._1 | |
180 | + | let pmtAssetNameA = $t049144991._2 | |
181 | + | let pmtDecimalsA = $t049144991._3 | |
182 | + | let $t049965073 = getAssetInfo(pmtAssetIdB) | |
183 | + | let pmtStrAssetIdB = $t049965073._1 | |
184 | + | let pmtAssetNameB = $t049965073._2 | |
185 | + | let pmtDecimalsB = $t049965073._3 | |
186 | + | if (isDefined(getBoolean(this, keyActive))) | |
187 | + | then throw("DApp is already active") | |
304 | 188 | else if ((pmtAssetIdA == pmtAssetIdB)) | |
305 | 189 | then throw("Assets must be different") | |
306 | 190 | else { | |
307 | 191 | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
308 | 192 | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
309 | 193 | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
310 | 194 | let shareInitialSupply = fraction(pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, HALFDOWN), pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, HALFDOWN), pow(10, 0, shareDecimals, 0, 0, HALFDOWN)) | |
311 | 195 | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
312 | 196 | let shareIssueId = calculateAssetId(shareIssue) | |
313 | - | let invariantCalculated = invariantCalc(pmtAmountA, pmtAmountB) | |
314 | - | [StringEntry(kVersion, version), BooleanEntry(kActive, true), StringEntry(kAssetIdA, pmtStrAssetIdA), StringEntry(kAssetIdB, pmtStrAssetIdB), IntegerEntry(kBalanceA, pmtAmountA), IntegerEntry(kBalanceB, pmtAmountB), IntegerEntry(kInvariant, invariantCalculated), IntegerEntry(kFee, fee), IntegerEntry(kFeeScaleDelimiter, feeScale6), shareIssue, StringEntry(kShareAssetId, toBase58String(shareIssueId)), IntegerEntry(kShareAssetSupply, shareInitialSupply), ScriptTransfer(i.caller, shareInitialSupply, shareIssueId)] | |
197 | + | [StringEntry(keyVersion, version), BooleanEntry(keyActive, true), StringEntry(keyAssetIdA, pmtStrAssetIdA), StringEntry(keyAssetIdB, pmtStrAssetIdB), IntegerEntry(keyBalanceA, pmtAmountA), IntegerEntry(keyBalanceB, pmtAmountB), IntegerEntry(keyCommission, commission), IntegerEntry(keyCommissionScaleDelimiter, commissionScaleDelimiter), shareIssue, StringEntry(keyShareAssetId, toBase58String(shareIssueId)), IntegerEntry(keyShareAssetSupply, shareInitialSupply), ScriptTransfer(i.caller, shareInitialSupply, shareIssueId)] | |
315 | 198 | } | |
316 | 199 | } | |
317 | 200 | ||
318 | 201 | ||
319 | 202 | ||
320 | 203 | @Callable(i) | |
321 | 204 | func replenishWithTwoTokens (slippageTolerance) = { | |
322 | 205 | let pmtAssetIdA = i.payments[0].assetId | |
323 | 206 | let pmtAssetIdB = i.payments[1].assetId | |
324 | 207 | let pmtAmountA = deductStakingFee(i.payments[0].amount, pmtAssetIdA) | |
325 | 208 | let pmtAmountB = deductStakingFee(i.payments[1].amount, pmtAssetIdB) | |
326 | - | let tokenRatio = fraction(fraction(scale8, balanceA, pmtAmountA), scale3, fraction(scale8, balanceB, pmtAmountB)) | |
327 | - | let ratioShareTokensInA = fraction(scale8, pmtAmountA, balanceA) | |
328 | - | let ratioShareTokensInB = fraction(scale8, pmtAmountB, balanceB) | |
329 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
330 | - | let invariantCalculated = invariantCalc((balanceA + pmtAmountA), (balanceB + pmtAmountB)) | |
209 | + | let tokenRatio = fraction(fraction(balanceA, scaleValue8, pmtAmountA), scaleValue3, fraction(balanceB, scaleValue8, pmtAmountB)) | |
210 | + | let ratioShareTokensInA = fraction(pmtAmountA, scaleValue8, balanceA) | |
211 | + | let ratioShareTokensInB = fraction(pmtAmountB, scaleValue8, balanceB) | |
212 | + | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scaleValue8) | |
331 | 213 | if (!(isActive)) | |
332 | - | then | |
214 | + | then throw("DApp is inactive at this moment") | |
333 | 215 | else if (if ((0 > slippageTolerance)) | |
334 | 216 | then true | |
335 | - | else (slippageTolerance > | |
336 | - | then throw("Slippage tolerance must be | |
217 | + | else (slippageTolerance > slippageToleranceDelimiter)) | |
218 | + | then throw(((("Slippage tolerance must be between 0 and " + toString(slippageToleranceDelimiter)) + " inclusively. Actual: ") + toString(slippageTolerance))) | |
337 | 219 | else if ((size(i.payments) != 2)) | |
338 | 220 | then throw("Two attached assets expected") | |
339 | 221 | else if (if ((pmtAssetIdA != assetIdA)) | |
340 | 222 | then true | |
341 | 223 | else (pmtAssetIdB != assetIdB)) | |
342 | - | then | |
343 | - | else if (if (((( | |
224 | + | then throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
225 | + | else if (if ((((scaleValue3 * (slippageToleranceDelimiter - slippageTolerance)) / slippageToleranceDelimiter) > tokenRatio)) | |
344 | 226 | then true | |
345 | - | else (tokenRatio > (( | |
227 | + | else (tokenRatio > ((scaleValue3 * (slippageToleranceDelimiter + slippageTolerance)) / slippageToleranceDelimiter))) | |
346 | 228 | then throw("Incorrect assets amount: amounts must have the contract ratio") | |
347 | 229 | else if ((shareTokenToPayAmount == 0)) | |
348 | 230 | then throw("Too small amount to replenish") | |
349 | 231 | else if (!(hasEnoughBalance)) | |
350 | - | then suspendSuspicious() | |
351 | - | else [IntegerEntry(kBalanceA, (balanceA + pmtAmountA)), IntegerEntry(kBalanceB, (balanceB + pmtAmountB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), IntegerEntry(kInvariant, invariantCalculated), Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId)] | |
352 | - | } | |
353 | - | ||
354 | - | ||
355 | - | ||
356 | - | @Callable(i) | |
357 | - | func replenishWithOneToken (virtualSwapTokenPay,virtualSwapTokenGet) = { | |
358 | - | let $t01293213007 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
359 | - | let pmtAmount = $t01293213007._1 | |
360 | - | let pmtAssetId = $t01293213007._2 | |
361 | - | let pmtMinThreshold = 5000000 | |
362 | - | let thresholdValueForMinTolerance = 50000000 | |
363 | - | let tolerance = if ((thresholdValueForMinTolerance > pmtAmount)) | |
364 | - | then 100000 | |
365 | - | else 1 | |
366 | - | let slippageValueMinForReplenish = (scale8 - ((scale8 * tolerance) / 10000000)) | |
367 | - | let slippageValueMaxForReplenish = (scale8 + ((scale8 * tolerance) / 10000000)) | |
368 | - | let slippageValueMinForSwap = (scale8 - ((scale8 * 1) / 10000000)) | |
369 | - | let slippageValueMaxForSwap = (scale8 + ((scale8 * 1) / 10000000)) | |
370 | - | if (!(isActive)) | |
371 | - | then throwIsInactive() | |
372 | - | else if ((pmtMinThreshold > pmtAmount)) | |
373 | - | then throw((((("Payment amount " + toString(pmtAmount)) + " does not exceed the minimum amount of ") + toString(pmtMinThreshold)) + " tokens")) | |
374 | - | else if ((size(i.payments) != 1)) | |
375 | - | then throw("One attached payment expected") | |
376 | - | else if (!(hasEnoughBalance)) | |
377 | - | then suspendSuspicious() | |
378 | - | else if (if ((pmtAssetId != assetIdA)) | |
379 | - | then (pmtAssetId != assetIdB) | |
380 | - | else false) | |
381 | - | then throwAssets() | |
382 | - | else { | |
383 | - | let $t01400914774 = if ((pmtAssetId == assetIdA)) | |
384 | - | then $Tuple7((pmtAmount - virtualSwapTokenPay), virtualSwapTokenGet, (balanceA + virtualSwapTokenPay), (balanceB - virtualSwapTokenGet), invariantCalc((balanceA + pmtAmount), balanceB), (balanceA + pmtAmount), balanceB) | |
385 | - | else $Tuple7(virtualSwapTokenGet, (pmtAmount - virtualSwapTokenPay), (balanceA - virtualSwapTokenGet), (balanceB + virtualSwapTokenPay), invariantCalc(balanceA, (balanceB + pmtAmount)), balanceA, (balanceB + pmtAmount)) | |
386 | - | let virtualReplenishA = $t01400914774._1 | |
387 | - | let virtualReplenishB = $t01400914774._2 | |
388 | - | let balanceAfterSwapA = $t01400914774._3 | |
389 | - | let balanceAfterSwapB = $t01400914774._4 | |
390 | - | let invariantCalculated = $t01400914774._5 | |
391 | - | let newBalanceA = $t01400914774._6 | |
392 | - | let newBalanceB = $t01400914774._7 | |
393 | - | let newBalanceEntry = if ((pmtAssetId == assetIdA)) | |
394 | - | then IntegerEntry(kBalanceA, newBalanceA) | |
395 | - | else IntegerEntry(kBalanceB, newBalanceB) | |
396 | - | let invariantNew = invariantCalc(balanceAfterSwapA, balanceAfterSwapB) | |
397 | - | let invariantEstimatedRatio = fraction(scale8, invariant, invariantNew) | |
398 | - | let ratioVirtualBalanceToVirtualReplenish = (fraction((scale8 * scale8), balanceAfterSwapA, balanceAfterSwapB) / fraction(scale8, virtualReplenishA, virtualReplenishB)) | |
399 | - | let dAppThresholdAmount = fraction((newBalanceA + newBalanceB), dAppThreshold, (2 * dAppThresholdScale2)) | |
400 | - | if (if ((slippageValueMinForSwap >= invariantEstimatedRatio)) | |
401 | - | then true | |
402 | - | else (invariant > invariantNew)) | |
403 | - | then throw("Incorrect virtualSwapTokenPay or virtualSwapTokenGet value") | |
404 | - | else if (if ((slippageValueMinForReplenish > ratioVirtualBalanceToVirtualReplenish)) | |
405 | - | then true | |
406 | - | else (ratioVirtualBalanceToVirtualReplenish > slippageValueMaxForReplenish)) | |
407 | - | then throw("Swap with virtualSwapTokenPay and virtualSwapTokenGet is possible, but ratio after virtual swap is incorrect") | |
408 | - | else if (if ((dAppThresholdAmount > newBalanceA)) | |
409 | - | then true | |
410 | - | else (dAppThresholdAmount > newBalanceB)) | |
411 | - | then throwThreshold(dAppThresholdAmount, newBalanceA, newBalanceB) | |
412 | - | else { | |
413 | - | let ratioShareTokensInA = fraction(deductStakingFee(virtualReplenishA, assetIdA), scale8, balanceAfterSwapA) | |
414 | - | let ratioShareTokensInB = fraction(deductStakingFee(virtualReplenishB, assetIdB), scale8, balanceAfterSwapB) | |
415 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
416 | - | [Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), newBalanceEntry, IntegerEntry(kInvariant, invariantCalculated)] | |
417 | - | } | |
418 | - | } | |
232 | + | then suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
233 | + | else [IntegerEntry(keyBalanceA, (balanceA + pmtAmountA)), IntegerEntry(keyBalanceB, (balanceB + pmtAmountB)), IntegerEntry(keyShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId)] | |
419 | 234 | } | |
420 | 235 | ||
421 | 236 | ||
422 | 237 | ||
423 | 238 | @Callable(i) | |
424 | 239 | func withdraw () = { | |
425 | - | let $ | |
426 | - | let pmtAmount = $ | |
427 | - | let pmtAssetId = $ | |
240 | + | let $t092679417 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
241 | + | let pmtAmount = $t092679417._1 | |
242 | + | let pmtAssetId = $t092679417._2 | |
428 | 243 | let amountToPayA = deductStakingFee(fraction(pmtAmount, balanceA, shareAssetSupply), assetIdA) | |
429 | 244 | let amountToPayB = deductStakingFee(fraction(pmtAmount, balanceB, shareAssetSupply), assetIdB) | |
430 | - | let invariantCalculated = invariantCalc((balanceA - amountToPayA), (balanceB - amountToPayB)) | |
431 | 245 | if (!(isActive)) | |
432 | - | then | |
246 | + | then throw("DApp is inactive at this moment") | |
433 | 247 | else if ((size(i.payments) != 1)) | |
434 | 248 | then throw("One attached payment expected") | |
435 | 249 | else if ((pmtAssetId != shareAssetId)) | |
436 | 250 | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
437 | 251 | else if (!(hasEnoughBalance)) | |
438 | - | then | |
252 | + | then suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
439 | 253 | else if (if ((amountToPayA > availableBalanceA)) | |
440 | 254 | then true | |
441 | 255 | else (amountToPayB > availableBalanceB)) | |
442 | 256 | then throwInsufficientAvailableBalances(amountToPayA, amountToPayB) | |
443 | - | else [IntegerEntry( | |
257 | + | else [IntegerEntry(keyBalanceA, (balanceA - amountToPayA)), IntegerEntry(keyBalanceB, (balanceB - amountToPayB)), IntegerEntry(keyShareAssetSupply, (shareAssetSupply - pmtAmount)), Burn(shareAssetId, pmtAmount), ScriptTransfer(i.caller, amountToPayA, assetIdA), ScriptTransfer(i.caller, amountToPayB, assetIdB)] | |
444 | 258 | } | |
445 | 259 | ||
446 | 260 | ||
447 | 261 | ||
448 | 262 | @Callable(i) | |
449 | - | func exchange (estimatedAmountToReceive,minAmountToReceive) = { | |
450 | - | let $t01835318428 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
451 | - | let pmtAmount = $t01835318428._1 | |
452 | - | let pmtAssetId = $t01835318428._2 | |
263 | + | func exchange (minAmountToReceive) = { | |
264 | + | let $t01080710882 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
265 | + | let pmtAmount = $t01080710882._1 | |
266 | + | let pmtAssetId = $t01080710882._2 | |
267 | + | func calculateFees (tokenFrom,tokenTo) = { | |
268 | + | let amountWithoutFee = fraction(tokenTo, pmtAmount, (pmtAmount + tokenFrom)) | |
269 | + | let amountWithFee = fraction(amountWithoutFee, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
270 | + | let governanceReward = fraction(amountWithoutFee, commissionGovernance, commissionScaleDelimiter) | |
271 | + | if ((minAmountToReceive > amountWithFee)) | |
272 | + | then throw(((("Calculated amount to receive " + toString(amountWithFee)) + " is less than specified minimum ") + toString(minAmountToReceive))) | |
273 | + | else $Tuple3(amountWithoutFee, amountWithFee, governanceReward) | |
274 | + | } | |
275 | + | ||
453 | 276 | if (!(isActive)) | |
454 | - | then throwIsInactive() | |
455 | - | else if ((0 >= estimatedAmountToReceive)) | |
456 | - | then throw(("Estimated amount must be positive. Actual: " + toString(estimatedAmountToReceive))) | |
457 | - | else if ((minAmountToReceive > estimatedAmountToReceive)) | |
458 | - | then throw(((("Minimal amount can't be greater than estimated. Estimated: " + toString(estimatedAmountToReceive)) + ". Minimal: ") + toString(minAmountToReceive))) | |
459 | - | else if ((size(i.payments) != 1)) | |
460 | - | then throw("One attached payment expected") | |
461 | - | else if (!(hasEnoughBalance)) | |
462 | - | then suspendSuspicious() | |
463 | - | else if (if ((pmtAssetId != assetIdA)) | |
464 | - | then (pmtAssetId != assetIdB) | |
465 | - | else false) | |
466 | - | then throwAssets() | |
467 | - | else if ((10000000 > pmtAmount)) | |
468 | - | then throw("Only swap of 10.000000 or more tokens is allowed") | |
469 | - | else if (if ((exchangeRatioLimitMin > fraction(scale8, minAmountToReceive, pmtAmount))) | |
277 | + | then throw("DApp is inactive at this moment") | |
278 | + | else if ((0 >= minAmountToReceive)) | |
279 | + | then throw(("Minimal amount to receive must be positive. Actual: " + toString(minAmountToReceive))) | |
280 | + | else if ((size(i.payments) != 1)) | |
281 | + | then throw("One attached payment expected") | |
282 | + | else if (!(hasEnoughBalance)) | |
283 | + | then suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB) + ". State: ") + toString(accountBalance(assetIdA))) + " ") + assetNameA) + ", ") + toString(accountBalance(assetIdB))) + " ") + assetNameB)) | |
284 | + | else if ((pmtAssetId == assetIdA)) | |
285 | + | then { | |
286 | + | let assetIdSend = assetIdB | |
287 | + | let $t01224112332 = calculateFees(balanceA, balanceB) | |
288 | + | let amountWithoutFee = $t01224112332._1 | |
289 | + | let amountWithFee = $t01224112332._2 | |
290 | + | let governanceReward = $t01224112332._3 | |
291 | + | let newBalanceA = (balanceA + pmtAmount) | |
292 | + | let newBalanceB = ((balanceB - amountWithFee) - governanceReward) | |
293 | + | if (if (if ((assetIdA == USDN)) | |
294 | + | then (stakedAmountUSDN >= newBalanceA) | |
295 | + | else false) | |
296 | + | then true | |
297 | + | else if ((assetIdB == USDN)) | |
298 | + | then (stakedAmountUSDN >= newBalanceB) | |
299 | + | else false) | |
300 | + | then throwInsufficientAvailableBalance(amountWithFee, availableBalanceB, assetNameB) | |
301 | + | else [IntegerEntry(keyBalanceA, newBalanceA), IntegerEntry(keyBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(governanceAddress, governanceReward, assetIdSend)] | |
302 | + | } | |
303 | + | else if ((pmtAssetId == assetIdB)) | |
304 | + | then { | |
305 | + | let assetIdSend = assetIdA | |
306 | + | let $t01320513296 = calculateFees(balanceB, balanceA) | |
307 | + | let amountWithoutFee = $t01320513296._1 | |
308 | + | let amountWithFee = $t01320513296._2 | |
309 | + | let governanceReward = $t01320513296._3 | |
310 | + | let newBalanceA = ((balanceA - amountWithFee) - governanceReward) | |
311 | + | let newBalanceB = (balanceB + pmtAmount) | |
312 | + | if (if (if ((assetIdA == USDN)) | |
313 | + | then (stakedAmountUSDN >= newBalanceA) | |
314 | + | else false) | |
470 | 315 | then true | |
471 | - | else (fraction(scale8, estimatedAmountToReceive, pmtAmount) > exchangeRatioLimitMax)) | |
472 | - | then throw("Incorrect args and pmt ratio") | |
473 | - | else { | |
474 | - | let sendAssetId = if ((pmtAssetId == assetIdA)) | |
475 | - | then assetIdB | |
476 | - | else assetIdA | |
477 | - | let amount = calculateSendAmount(estimatedAmountToReceive, minAmountToReceive, pmtAmount, pmtAssetId) | |
478 | - | let governanceReward = fraction(amount, feeGovernance, feeScale6) | |
479 | - | let amountMinusFee = fraction(amount, (feeScale6 - fee), feeScale6) | |
480 | - | let $t01977920042 = if ((pmtAssetId == assetIdA)) | |
481 | - | then $Tuple2((balanceA + pmtAmount), ((balanceB - amountMinusFee) - governanceReward)) | |
482 | - | else $Tuple2(((balanceA - amountMinusFee) - governanceReward), (balanceB + pmtAmount)) | |
483 | - | let newBalanceA = $t01977920042._1 | |
484 | - | let newBalanceB = $t01977920042._2 | |
485 | - | let dAppThresholdAmount = fraction((newBalanceA + newBalanceB), dAppThreshold, (2 * dAppThresholdScale2)) | |
486 | - | if (if ((dAppThresholdAmount > newBalanceA)) | |
487 | - | then true | |
488 | - | else (dAppThresholdAmount > newBalanceB)) | |
489 | - | then throwThreshold(dAppThresholdAmount, newBalanceA, newBalanceB) | |
490 | - | else if (if (if ((assetIdA == USDN)) | |
491 | - | then (sendAssetId == assetIdA) | |
492 | - | else false) | |
493 | - | then (stakedAmountUSDN >= newBalanceA) | |
494 | - | else false) | |
495 | - | then throwInsufficientAvailableBalance(amountMinusFee, availableBalanceA, assetNameA) | |
496 | - | else if (if (if ((assetIdB == USDN)) | |
497 | - | then (sendAssetId == assetIdB) | |
498 | - | else false) | |
499 | - | then (stakedAmountUSDN >= newBalanceB) | |
500 | - | else false) | |
501 | - | then throwInsufficientAvailableBalance(amountMinusFee, availableBalanceB, assetNameB) | |
502 | - | else [IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), IntegerEntry(kInvariant, invariantCalc(newBalanceA, newBalanceB)), ScriptTransfer(i.caller, amountMinusFee, sendAssetId), ScriptTransfer(govAddr, governanceReward, sendAssetId)] | |
503 | - | } | |
316 | + | else if ((assetIdB == USDN)) | |
317 | + | then (stakedAmountUSDN >= newBalanceB) | |
318 | + | else false) | |
319 | + | then throwInsufficientAvailableBalance(amountWithFee, availableBalanceA, assetNameA) | |
320 | + | else [IntegerEntry(keyBalanceA, newBalanceA), IntegerEntry(keyBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(governanceAddress, governanceReward, assetIdSend)] | |
321 | + | } | |
322 | + | else throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
504 | 323 | } | |
505 | 324 | ||
506 | 325 | ||
507 | 326 | ||
508 | 327 | @Callable(i) | |
509 | 328 | func shutdown () = if (!(isActive)) | |
510 | - | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, | |
511 | - | else if (!(containsElement([ | |
512 | - | then | |
329 | + | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, keyCause), "the cause wasn't specified"))) | |
330 | + | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminPubKeyStartStop], i.callerPublicKey))) | |
331 | + | then throw("Only admin can call this function") | |
513 | 332 | else suspend("Paused by admin") | |
514 | 333 | ||
515 | 334 | ||
516 | 335 | ||
517 | 336 | @Callable(i) | |
518 | 337 | func activate () = if (isActive) | |
519 | - | then | |
520 | - | else if (!(containsElement([ | |
521 | - | then | |
522 | - | else [BooleanEntry( | |
338 | + | then throw("DApp is already active") | |
339 | + | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminPubKeyStartStop], i.callerPublicKey))) | |
340 | + | then throw("Only admin can call this function") | |
341 | + | else [BooleanEntry(keyActive, true), DeleteEntry(keyCause)] | |
523 | 342 | ||
524 | 343 | ||
525 | 344 | ||
526 | 345 | @Callable(i) | |
527 | 346 | func takeIntoAccountExtraFunds (amountLeave) = { | |
528 | - | let | |
529 | - | let | |
530 | - | let amountEnrollA = ( | |
347 | + | let uncountableAmountEnrollAssetA = (accountBalanceWithStakedA - balanceA) | |
348 | + | let uncountableAmountEnrollAssetB = (accountBalanceWithStakedB - balanceB) | |
349 | + | let amountEnrollA = (uncountableAmountEnrollAssetA - (if ((assetIdA == USDN)) | |
531 | 350 | then amountLeave | |
532 | 351 | else 0)) | |
533 | - | let amountEnrollB = ( | |
352 | + | let amountEnrollB = (uncountableAmountEnrollAssetB - (if ((assetIdB == USDN)) | |
534 | 353 | then amountLeave | |
535 | 354 | else 0)) | |
536 | 355 | if (!(isActive)) | |
537 | - | then | |
356 | + | then throw("DApp is inactive at this moment") | |
538 | 357 | else if ((i.caller != this)) | |
539 | - | then | |
358 | + | then throw("Only the DApp itself can call this function") | |
540 | 359 | else if ((0 > amountLeave)) | |
541 | 360 | then throw(("Argument 'amountLeave' cannot be negative. Actual: " + toString(amountLeave))) | |
542 | - | else if (if ((0 > | |
361 | + | else if (if ((0 > uncountableAmountEnrollAssetA)) | |
543 | 362 | then true | |
544 | - | else (0 > | |
363 | + | else (0 > uncountableAmountEnrollAssetB)) | |
545 | 364 | then suspend("Enroll amount negative") | |
546 | 365 | else if (if ((0 > amountEnrollA)) | |
547 | 366 | then true | |
548 | 367 | else (0 > amountEnrollB)) | |
549 | 368 | then throw("Too large amountLeave") | |
550 | - | else [IntegerEntry( | |
369 | + | else [IntegerEntry(keyBalanceA, (balanceA + amountEnrollA)), IntegerEntry(keyBalanceB, (balanceB + amountEnrollB)), IntegerEntry(("last_income_" + strAssetIdA), amountEnrollA), IntegerEntry(("last_income_" + strAssetIdB), amountEnrollB)] | |
551 | 370 | } | |
552 | 371 | ||
553 | 372 | ||
554 | 373 | @Verifier(tx) | |
555 | 374 | func verify () = match tx { | |
556 | 375 | case invoke: InvokeScriptTransaction => | |
557 | 376 | let callTakeIntoAccount = if ((invoke.dApp == this)) | |
558 | 377 | then (invoke.function == "takeIntoAccountExtraFunds") | |
559 | 378 | else false | |
560 | 379 | let callStaking = if ((invoke.dApp == stakingAddress)) | |
561 | 380 | then if (if (if ((invoke.function == "lockNeutrino")) | |
562 | 381 | then (size(invoke.payments) == 1) | |
563 | 382 | else false) | |
564 | 383 | then (invoke.payments[0].assetId == USDN) | |
565 | 384 | else false) | |
566 | 385 | then true | |
567 | 386 | else if ((invoke.function == "unlockNeutrino")) | |
568 | 387 | then (size(invoke.payments) == 0) | |
569 | 388 | else false | |
570 | 389 | else false | |
571 | - | let signedByAdmin = if (if (if (sigVerify(tx.bodyBytes, tx.proofs[0], | |
390 | + | let signedByAdmin = if (if (if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
572 | 391 | then true | |
573 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], | |
392 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey2)) | |
574 | 393 | then true | |
575 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], | |
394 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey3)) | |
576 | 395 | then true | |
577 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], | |
396 | + | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKeyStaking) | |
578 | 397 | if (callTakeIntoAccount) | |
579 | 398 | then true | |
580 | 399 | else callStaking | |
581 | 400 | case _ => | |
582 | 401 | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
583 | 402 | } | |
584 | 403 |
github/deemru/w8io/169f3d6 119.42 ms ◑