tx · BN14Vfd9aoDBtQospVDznCoZboQsFZ5bmmSTPvtknHZD 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h: -0.05000000 Waves 2023.03.28 09:07 [2509419] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves
{ "type": 13, "id": "BN14Vfd9aoDBtQospVDznCoZboQsFZ5bmmSTPvtknHZD", "fee": 5000000, "feeAssetId": null, "timestamp": 1679983612490, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "5AWvRHscQr9hd83x7AszE5T56am9E6RdBjE96bsZKw7odnAW7caDPQG5whqXXwSJ2sAV4hd5RqrnHHCxNvPHnKa1" ], "script": "base64:BgIPCAISABIAEgASBQoDAQEBCwAMY29udHJhY3RGaWxlAglyZWJhbGFuY2UAD2tleXNUYXJnZXRSYXRpbwIPJXNfX3RhcmdldFJhdGlvABRrZXlBZGRpdGlvbmFsQmFsYW5jZQIaJXNfX2FkZGl0aW9uYWxXYXZlc0JhbGFuY2UAGmtleVNXYXZlc0FkZGl0aW9uYWxCYWxhbmNlAhElc19fc1dhdmVzQmFsYW5jZQAQa2V5U1dhdmVzQXNzZXRJZAIRJXNfX3NXYXZlc0Fzc2V0SWQAD2tleVByb3h5QWRkcmVzcwIQJXNfX3Byb3h5QWRkcmVzcwEQZ2V0SW50ZWdlck9yWmVybwEKaW50ZWdlcktleQQHJG1hdGNoMAkAmggCBQR0aGlzBQppbnRlZ2VyS2V5AwkAAQIFByRtYXRjaDACA0ludAQDdmFsBQckbWF0Y2gwBQN2YWwAAAEQZ2V0U3RyaW5nT3JUaHJvdwEJc3RyaW5nS2V5BAckbWF0Y2gwCQCdCAIFBHRoaXMFCXN0cmluZ0tleQMJAAECBQckbWF0Y2gwAgZTdHJpbmcEAXMFByRtYXRjaDAFAXMJAAIB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GVnZXJPclplcm8BBRRrZXlBZGRpdGlvbmFsQmFsYW5jZQQFcmF0aW8JAGsDAGQFCmFkZGl0aW9uYWwJAGQCBQphZGRpdGlvbmFsBRNyZWd1bGFyV2F2ZXNCYWxhbmNlCQCUCgIFA25pbAUFcmF0aW8BaQENY2FsY1JhdGlvVGVzdAMOcmVndWxhckJhbGFuY2UKYWRkaXRpb25hbAt0YXJnZXRSYXRpbwQDc3VtCQBkAgUOcmVndWxhckJhbGFuY2UFCmFkZGl0aW9uYWwEF3RhcmdldEFkZGl0aW9uYWxCYWxhbmNlCQBrAwULdGFyZ2V0UmF0aW8FA3N1bQBkBAZjaGFuZ2UJAGUCBQphZGRpdGlvbmFsBRd0YXJnZXRBZGRpdGlvbmFsQmFsYW5jZQQGbmV3UmVnCQBkAgUOcmVndWxhckJhbGFuY2UFBmNoYW5nZQMJAGYCAAAFBmNoYW5nZQQKc2VuZEFtb3VudAkAaAIFBmNoYW5nZQD///////////8BCQCUCgIFA25pbAkAzAgCBQZuZXdSZWcJAMwIAgUXdGFyZ2V0QWRkaXRpb25hbEJhbGFuY2UJAMwIAgUGY2hhbmdlCQDMCAIJAKwCAgIJZGVwb3NpdDogCQCkAwEFCnNlbmRBbW91bnQFA25pbAQKc2VuZEFtb3VudAUGY2hhbmdlCQCUCgIFA25pbAkAzAgCBQZuZXdSZWcJAMwIAgUXdGFyZ2V0QWRkaXRpb25hbEJhbGFuY2UJAMwIAgUGY2hhbmdlCQDMCAIJAKwCAgIKd2l0aGRyYXc6IAkApAMBBQpzZW5kQW1vdW50BQNuaWwACqIZjw==", "height": 2509419, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6qZasWNEcJVm1eUmdNVzTegkBZVf4PBbf7BsRfchMfJB Next: FQR71EwWYET2D37rV9cyPQy9c57AsVrLSPBFetrAPMsk Diff:
Old | New | Differences | |
---|---|---|---|
37 | 37 | let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
38 | 38 | if ((additionalBalance == 0)) | |
39 | 39 | then 0 | |
40 | - | else fraction( | |
40 | + | else fraction(100000000000, additionalBalance, sWavesBalance) | |
41 | 41 | } | |
42 | 42 | ||
43 | 43 | ||
44 | 44 | func getRate () = { | |
45 | 45 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
46 | - | invoke(proxy, "getRate", nil, nil) | |
46 | + | let inv = invoke(proxy, "getRate", nil, nil) | |
47 | + | if ((inv == inv)) | |
48 | + | then match inv { | |
49 | + | case s: String => | |
50 | + | parseIntValue(s) | |
51 | + | case _ => | |
52 | + | 0 | |
53 | + | } | |
54 | + | else throw("Strict value is not equal to itself.") | |
47 | 55 | } | |
48 | 56 | ||
49 | 57 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let contractFile = "rebalance" | |
5 | 5 | ||
6 | 6 | let keysTargetRatio = "%s__targetRatio" | |
7 | 7 | ||
8 | 8 | let keyAdditionalBalance = "%s__additionalWavesBalance" | |
9 | 9 | ||
10 | 10 | let keySWavesAdditionalBalance = "%s__sWavesBalance" | |
11 | 11 | ||
12 | 12 | let keySWavesAssetId = "%s__sWavesAssetId" | |
13 | 13 | ||
14 | 14 | let keyProxyAddress = "%s__proxyAddress" | |
15 | 15 | ||
16 | 16 | func getIntegerOrZero (integerKey) = match getInteger(this, integerKey) { | |
17 | 17 | case val: Int => | |
18 | 18 | val | |
19 | 19 | case _ => | |
20 | 20 | 0 | |
21 | 21 | } | |
22 | 22 | ||
23 | 23 | ||
24 | 24 | func getStringOrThrow (stringKey) = match getString(this, stringKey) { | |
25 | 25 | case s: String => | |
26 | 26 | s | |
27 | 27 | case _ => | |
28 | 28 | throw((("[" + stringKey) + "] is empty")) | |
29 | 29 | } | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func internalWavesBalance () = (wavesBalance(this).regular + getIntegerOrZero(keyAdditionalBalance)) | |
33 | 33 | ||
34 | 34 | ||
35 | 35 | func currentRate () = { | |
36 | 36 | let additionalBalance = getIntegerOrZero(keyAdditionalBalance) | |
37 | 37 | let sWavesBalance = getIntegerOrZero(keySWavesAdditionalBalance) | |
38 | 38 | if ((additionalBalance == 0)) | |
39 | 39 | then 0 | |
40 | - | else fraction( | |
40 | + | else fraction(100000000000, additionalBalance, sWavesBalance) | |
41 | 41 | } | |
42 | 42 | ||
43 | 43 | ||
44 | 44 | func getRate () = { | |
45 | 45 | let proxy = addressFromStringValue(getStringOrThrow(keyProxyAddress)) | |
46 | - | invoke(proxy, "getRate", nil, nil) | |
46 | + | let inv = invoke(proxy, "getRate", nil, nil) | |
47 | + | if ((inv == inv)) | |
48 | + | then match inv { | |
49 | + | case s: String => | |
50 | + | parseIntValue(s) | |
51 | + | case _ => | |
52 | + | 0 | |
53 | + | } | |
54 | + | else throw("Strict value is not equal to itself.") | |
47 | 55 | } | |
48 | 56 | ||
49 | 57 | ||
50 | 58 | @Callable(i) | |
51 | 59 | func returnWavesBalance () = $Tuple2(nil, internalWavesBalance()) | |
52 | 60 | ||
53 | 61 | ||
54 | 62 | ||
55 | 63 | @Callable(i) | |
56 | 64 | func returnSWavesBalance () = $Tuple2(nil, getIntegerOrZero(keySWavesAdditionalBalance)) | |
57 | 65 | ||
58 | 66 | ||
59 | 67 | ||
60 | 68 | @Callable(i) | |
61 | 69 | func calcRatio () = { | |
62 | 70 | let regularWavesBalance = wavesBalance(this).regular | |
63 | 71 | let additional = getIntegerOrZero(keyAdditionalBalance) | |
64 | 72 | let ratio = fraction(100, additional, (additional + regularWavesBalance)) | |
65 | 73 | $Tuple2(nil, ratio) | |
66 | 74 | } | |
67 | 75 | ||
68 | 76 | ||
69 | 77 | ||
70 | 78 | @Callable(i) | |
71 | 79 | func calcRatioTest (regularBalance,additional,targetRatio) = { | |
72 | 80 | let sum = (regularBalance + additional) | |
73 | 81 | let targetAdditionalBalance = fraction(targetRatio, sum, 100) | |
74 | 82 | let change = (additional - targetAdditionalBalance) | |
75 | 83 | let newReg = (regularBalance + change) | |
76 | 84 | if ((0 > change)) | |
77 | 85 | then { | |
78 | 86 | let sendAmount = (change * -1) | |
79 | 87 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("deposit: " + toString(sendAmount))]) | |
80 | 88 | } | |
81 | 89 | else { | |
82 | 90 | let sendAmount = change | |
83 | 91 | $Tuple2(nil, [newReg, targetAdditionalBalance, change, ("withdraw: " + toString(sendAmount))]) | |
84 | 92 | } | |
85 | 93 | } | |
86 | 94 | ||
87 | 95 |
github/deemru/w8io/026f985 24.25 ms ◑