tx · CaBgMmN1N2cmHyGWuRDWJzAUsy9i1uGbVF9p3xfHcUSQ 3N4revPn12feiSAyC78tAZEJfsyprVYPzsL: -0.01000000 Waves 2022.02.09 16:35 [1916159] smart account 3N4revPn12feiSAyC78tAZEJfsyprVYPzsL > SELF 0.00000000 Waves
{ "type": 13, "id": "CaBgMmN1N2cmHyGWuRDWJzAUsy9i1uGbVF9p3xfHcUSQ", "fee": 1000000, "feeAssetId": null, "timestamp": 1644413709118, "version": 2, "chainId": 84, "sender": "3N4revPn12feiSAyC78tAZEJfsyprVYPzsL", "senderPublicKey": "5smGxL7bfeRokaN53Z31Y72dF2Lkr5Cg1kuWRV3gniNe", "proofs": [ "4ncpz6Tesp5CNWPeejuqG6Wy14ctfYSePFZ1V1qGL4FTtamG1F9w1GuhGNYDZTu3THRARbwapDxjmQhJXL2ibQgr" ], "script": "base64:AAIFAAAAAAAAAAwIAhIICgYBAQEIAQEAAAAXAAAAAAtzdHJBc3NldElkQQIAAAAsMzROOVljRUVUTFduOTNxWVE2NEVzUDF4ODl0U3J1SlU0NFJyRU1TWFhFUEoAAAAAC3N0ckFzc2V0SWRCAgAAACxERzJ4RmtQZER3S1VvQmt6R0FoUXRMcFNHemZYTGlDWVBFemVLSDJBZDI0cAAAAAAIYXNzZXRJZEEDCQAAAAAAAAIFAAAAC3N0ckFzc2V0SWRBAgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAAtzdHJBc3NldElkQQAAAAAIYXNzZXRJZEIDCQAAAAAAAAIFAAAAC3N0ckFzc2V0SWRCAgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAAtzdHJBc3NldElkQgAAAAADZmVlAAAAAAAAAAH0AAAAAA1mZWVHb3Zlcm5hbmNlAAAAAAAAAADIAAAAAAlmZWVTY2FsZTYAAAAAAAAPQkAAAAAABnNjYWxlMwAAAAAAAAAD6AAAAAAGc2NhbGU4AAAAAAAF9eEAAAAAAAdzY2FsZTEyAAAAAOjUpRA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lmZWVTY2FsZTYFAAAAA2ZlZQUAAAAJZmVlU2NhbGU2CQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACAgAAAApzZW5kQW1vdW50BQAAAAZhbW91bnQJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAICAAAAF3NlbmRBbW91bnRXaXRoQ29taXNzaW9uBQAAAA5hbW91bnRNaW51c0ZlZQUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXnWNFP4", "height": 1916159, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: 4eRLGCvaQrT3UQnUEijT5svXFnojb73pPgqBBFV7ixd3 Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let strAssetIdA = "34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ" | |
5 | + | ||
6 | + | let strAssetIdB = "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p" | |
7 | + | ||
8 | + | let assetIdA = if ((strAssetIdA == "WAVES")) | |
9 | + | then unit | |
10 | + | else fromBase58String(strAssetIdA) | |
11 | + | ||
12 | + | let assetIdB = if ((strAssetIdB == "WAVES")) | |
13 | + | then unit | |
14 | + | else fromBase58String(strAssetIdB) | |
15 | + | ||
16 | + | let fee = 500 | |
17 | + | ||
18 | + | let feeGovernance = 200 | |
19 | + | ||
20 | + | let feeScale6 = 1000000 | |
21 | + | ||
22 | + | let scale3 = 1000 | |
23 | + | ||
24 | + | let scale8 = 100000000 | |
25 | + | ||
26 | + | let scale12 = 1000000000000 | |
27 | + | ||
28 | + | let slippageScale3 = 1000 | |
29 | + | ||
30 | + | let digits8 = 8 | |
31 | + | ||
32 | + | let digits12 = 12 | |
33 | + | ||
34 | + | let dAppThreshold = 50 | |
35 | + | ||
36 | + | let dAppThresholdScale2 = 100 | |
37 | + | ||
38 | + | let exchangeRatioLimitMin = 90000000 | |
39 | + | ||
40 | + | let exchangeRatioLimitMax = 110000000 | |
41 | + | ||
42 | + | let alpha = 50 | |
43 | + | ||
44 | + | let alphaDigits = 2 | |
45 | + | ||
46 | + | let beta = 460000000000 | |
47 | + | ||
48 | + | func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000) | |
49 | + | ||
50 | + | ||
51 | + | func invariantCalc (x,y) = { | |
52 | + | let sk = skewness(x, y) | |
53 | + | (fraction((x + y), scale8, pow(sk, digits8, alpha, alphaDigits, digits8, CEILING)) + (2 * fraction(pow(fraction(x, y, scale8), 0, 5, 1, (digits8 / 2), DOWN), pow((sk - beta), digits8, alpha, alphaDigits, digits8, DOWN), scale8))) | |
54 | + | } | |
55 | + | ||
56 | + | ||
57 | + | func calculateSendAmount (balanceA,balanceB,amountToSendEstimated,minTokenReceiveAmount,tokenReceiveAmount,tokenId) = { | |
58 | + | let slippageValue = (scale8 - ((scale8 * 1) / 10000000)) | |
59 | + | let deltaBetweenMaxAndMinSendValue = (amountToSendEstimated - minTokenReceiveAmount) | |
60 | + | let x = (balanceA + tokenReceiveAmount) | |
61 | + | let y = (balanceB + tokenReceiveAmount) | |
62 | + | let invariant = invariantCalc(balanceA, balanceB) | |
63 | + | let invariantNew = if ((tokenId == strAssetIdA)) | |
64 | + | then invariantCalc(x, (balanceB - amountToSendEstimated)) | |
65 | + | else if ((tokenId == strAssetIdB)) | |
66 | + | then invariantCalc((balanceA - amountToSendEstimated), y) | |
67 | + | else throw("Wrong asset in payment") | |
68 | + | let invariantEstimatedRatio = fraction(scale8, invariant, invariantNew) | |
69 | + | func getStepAmount (acc,step) = if ((acc == -1)) | |
70 | + | then { | |
71 | + | let amountToSend = (amountToSendEstimated - ((step * deltaBetweenMaxAndMinSendValue) / 5)) | |
72 | + | let stepInvariant = if ((tokenId == strAssetIdA)) | |
73 | + | then invariantCalc(x, (balanceB - amountToSend)) | |
74 | + | else invariantCalc((balanceA - amountToSend), y) | |
75 | + | if ((stepInvariant > invariant)) | |
76 | + | then amountToSend | |
77 | + | else -1 | |
78 | + | } | |
79 | + | else acc | |
80 | + | ||
81 | + | let stepAmount = { | |
82 | + | let $l = [1, 2, 3, 4, 5] | |
83 | + | let $s = size($l) | |
84 | + | let $acc0 = -1 | |
85 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
86 | + | then $a | |
87 | + | else getStepAmount($a, $l[$i]) | |
88 | + | ||
89 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
90 | + | then $a | |
91 | + | else throw("List size exceeds 5") | |
92 | + | ||
93 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5) | |
94 | + | } | |
95 | + | if ((0 > stepAmount)) | |
96 | + | then throw("something went wrong while working with amountToSend") | |
97 | + | else if (if ((invariantEstimatedRatio > slippageValue)) | |
98 | + | then (invariantNew > invariant) | |
99 | + | else false) | |
100 | + | then amountToSendEstimated | |
101 | + | else stepAmount | |
102 | + | } | |
103 | + | ||
104 | + | ||
105 | + | @Callable(i) | |
106 | + | func exchange (balanceA,balanceB,pmtAmount,pmtAssetId,estimatedAmountToReceive,minAmountToReceive) = { | |
107 | + | let amount = calculateSendAmount(balanceA, balanceB, estimatedAmountToReceive, minAmountToReceive, pmtAmount, pmtAssetId) | |
108 | + | let governanceReward = fraction(amount, feeGovernance, feeScale6) | |
109 | + | let amountMinusFee = fraction(amount, (feeScale6 - fee), feeScale6) | |
110 | + | [IntegerEntry("sendAmount", amount), IntegerEntry("sendAmountWithComission", amountMinusFee)] | |
111 | + | } | |
112 | + | ||
113 | + | ||
114 | + | @Verifier(tx) | |
115 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
116 | + |
github/deemru/w8io/169f3d6 24.74 ms ◑