tx · E2AYH9iR5teHM54BQBnsut7vra1dEtDS9zwSorEAccuK 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h: -0.05000000 Waves 2023.03.30 09:13 [2512311] smart account 3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h > SELF 0.00000000 Waves
{ "type": 13, "id": "E2AYH9iR5teHM54BQBnsut7vra1dEtDS9zwSorEAccuK", "fee": 5000000, "feeAssetId": null, "timestamp": 1680156845873, "version": 2, "chainId": 84, "sender": "3NCWFHDzdPHZC6636ZkMLNDup9mjpbTLs7h", "senderPublicKey": "3z8Q6Zu3KppVmn6fJJvrLc1Wo3krVHSvfaNcerm82md2", "proofs": [ "5pKsew2hsLqjxE86VvJFKr6o2wCwgeTQnGUuBhSv3NPPhj9W6EMgL2mFaCoENWT49AEE4qrfN5CkvxEmLZFsiL5i" ], "script": "base64:BgIHCAISAwoBCA0AA1NFUAICX18ADGNvbnRyYWN0RmlsZQIOcmViYWxhbmNlLnJpZGUAEWtleUZhY3RvcnlBZGRyZXNzAgslc19fZmFjdG9yeQEUa2V5QWRkaXRpb25hbEJhbGFuY2UBB2Fzc2V0SWQJALkJAgkAzAgCAgQlcyVzCQDMCAICEWFkZGl0aW9uYWxCYWxhbmNlCQDMCAIFB2Fzc2V0SWQFA25pbAUDU0VQARZrZXlTdGFraW5nQXNzZXRCYWxhbmNlAQdhc3NldElkCQC5CQIJAMwIAgIEJXMlcwkAzAgCAhNzdGFraW5nQXNzZXRCYWxhbmNlCQDMCAIFB2Fzc2V0SWQFA25pbAUDU0VQARRnZXRBZGRpdGlvbmFsQmFsYW5jZQEHYXNzZXRJZAkBC3ZhbHVlT3JFbHNlAgkAmggCBQR0aGlzCQEUa2V5QWRkaXRpb25hbEJhbGFuY2UBBQdhc3NldElkAAABFmdldFN0YWtpbmdBc3NldEJhbGFuY2UBB2Fzc2V0SWQJAQt2YWx1ZU9yRWxzZQIJAJoIAgUEdGhpcwkBFmtleVN0YWtpbmdBc3NldEJhbGF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SWQIBQskdDA0MzU2NDQ2NQJfNQQMcHJveHlSYXRlTXVsCAULJHQwNDM1NjQ0NjUCXzYEFHN0YWtpbmdQcm9maXRBZGRyZXNzCAULJHQwNDM1NjQ0NjUCXzcDBQppc0xlYXNhYmxlCQERcmViYWxhbmNlSW50ZXJuYWwGBQtsZWFzZWRSYXRpbwUHYXNzZXRJZAUMcHJveHlBc3NldElkBQptaW5CYWxhbmNlCQERQGV4dHJOYXRpdmUoMTA2MikBBQxwcm94eUFkZHJlc3MFDHByb3h5UmF0ZU11bAUDbmlsCQEKdGhyb3dFcnJvcgEJAKwCAgkArAICAgFbBQdhc3NldElkAhFdIFJlYmFsYW5jZSBlcnJvcgB7PO6B", "height": 2512311, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6qjiGmkGnHy9XM3BQwo6xgVdGx6go2qGNUPJvCvpBFnS Next: GctJ3TsQsEVdWkAXm937qNffDjiqwhJPuXKd1N9vyGes Diff:
Old | New | Differences | |
---|---|---|---|
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | - | let contractFile = "rebalance" | |
6 | + | let contractFile = "rebalance.ride" | |
7 | 7 | ||
8 | 8 | let keyFactoryAddress = "%s__factory" | |
9 | 9 | ||
19 | 19 | func getStakingAssetBalance (assetId) = valueOrElse(getInteger(this, keyStakingAssetBalance(assetId)), 0) | |
20 | 20 | ||
21 | 21 | ||
22 | + | func throwError (errorMsg) = throw(((contractFile + ": ") + errorMsg)) | |
23 | + | ||
24 | + | ||
22 | 25 | func getRate (proxy) = { | |
23 | 26 | let inv = invoke(proxy, "getRate", nil, nil) | |
24 | 27 | if ((inv == inv)) | |
26 | 29 | case s: String => | |
27 | 30 | parseIntValue(s) | |
28 | 31 | case _ => | |
29 | - | | |
32 | + | throwError("getRate() returned zero") | |
30 | 33 | } | |
31 | 34 | else throw("Strict value is not equal to itself.") | |
32 | 35 | } | |
142 | 145 | ||
143 | 146 | ||
144 | 147 | @Callable(i) | |
145 | - | func rebalance () = { | |
146 | - | let asset1 = "WAVES" | |
147 | - | match getLeaseProxyConfig(asset1) { | |
148 | - | case a: (Boolean, Int, Int, String, String, Int, String) => | |
149 | - | let $t042604369 = a | |
150 | - | let isLeasable = $t042604369._1 | |
151 | - | let leasedRatio = $t042604369._2 | |
152 | - | let minBalance = $t042604369._3 | |
153 | - | let proxyAddress = $t042604369._4 | |
154 | - | let proxyAssetId = $t042604369._5 | |
155 | - | let proxyRateMul = $t042604369._6 | |
156 | - | let stakingProfitAddress = $t042604369._7 | |
157 | - | if (isLeasable) | |
158 | - | then rebalanceInternal(leasedRatio, asset1, proxyAssetId, minBalance, addressFromStringValue(proxyAddress), proxyRateMul) | |
159 | - | else nil | |
160 | - | case _ => | |
161 | - | throw("BRR") | |
162 | - | } | |
163 | - | } | |
148 | + | func rebalanceAsset (assetId) = match getLeaseProxyConfig(assetId) { | |
149 | + | case a: (Boolean, Int, Int, String, String, Int, String) => | |
150 | + | let $t043564465 = a | |
151 | + | let isLeasable = $t043564465._1 | |
152 | + | let leasedRatio = $t043564465._2 | |
153 | + | let minBalance = $t043564465._3 | |
154 | + | let proxyAddress = $t043564465._4 | |
155 | + | let proxyAssetId = $t043564465._5 | |
156 | + | let proxyRateMul = $t043564465._6 | |
157 | + | let stakingProfitAddress = $t043564465._7 | |
158 | + | if (isLeasable) | |
159 | + | then rebalanceInternal(leasedRatio, assetId, proxyAssetId, minBalance, addressFromStringValue(proxyAddress), proxyRateMul) | |
160 | + | else nil | |
161 | + | case _ => | |
162 | + | throwError((("[" + assetId) + "] Rebalance error")) | |
163 | + | } | |
164 | 164 | ||
165 | 165 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | - | let contractFile = "rebalance" | |
6 | + | let contractFile = "rebalance.ride" | |
7 | 7 | ||
8 | 8 | let keyFactoryAddress = "%s__factory" | |
9 | 9 | ||
10 | 10 | func keyAdditionalBalance (assetId) = makeString(["%s%s", "additionalBalance", assetId], SEP) | |
11 | 11 | ||
12 | 12 | ||
13 | 13 | func keyStakingAssetBalance (assetId) = makeString(["%s%s", "stakingAssetBalance", assetId], SEP) | |
14 | 14 | ||
15 | 15 | ||
16 | 16 | func getAdditionalBalance (assetId) = valueOrElse(getInteger(this, keyAdditionalBalance(assetId)), 0) | |
17 | 17 | ||
18 | 18 | ||
19 | 19 | func getStakingAssetBalance (assetId) = valueOrElse(getInteger(this, keyStakingAssetBalance(assetId)), 0) | |
20 | 20 | ||
21 | 21 | ||
22 | + | func throwError (errorMsg) = throw(((contractFile + ": ") + errorMsg)) | |
23 | + | ||
24 | + | ||
22 | 25 | func getRate (proxy) = { | |
23 | 26 | let inv = invoke(proxy, "getRate", nil, nil) | |
24 | 27 | if ((inv == inv)) | |
25 | 28 | then match inv { | |
26 | 29 | case s: String => | |
27 | 30 | parseIntValue(s) | |
28 | 31 | case _ => | |
29 | - | | |
32 | + | throwError("getRate() returned zero") | |
30 | 33 | } | |
31 | 34 | else throw("Strict value is not equal to itself.") | |
32 | 35 | } | |
33 | 36 | ||
34 | 37 | ||
35 | 38 | func getLeaseProxyConfig (assetId) = { | |
36 | 39 | let factory = addressFromStringValue(valueOrElse(getString(keyFactoryAddress), "")) | |
37 | 40 | let myAddressString = toString(this) | |
38 | 41 | invoke(factory, "getPoolLeaseConfigREADONLY", [myAddressString, assetId], nil) | |
39 | 42 | } | |
40 | 43 | ||
41 | 44 | ||
42 | 45 | func deposit (assetId,amount,stakingAssetId,proxy) = { | |
43 | 46 | let currentAdditionalBalance = getAdditionalBalance(assetId) | |
44 | 47 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
45 | 48 | then { | |
46 | 49 | let currentStakingAssetBalance = getStakingAssetBalance(stakingAssetId) | |
47 | 50 | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
48 | 51 | then { | |
49 | 52 | let asset = if ((assetId == "WAVES")) | |
50 | 53 | then unit | |
51 | 54 | else fromBase58String(assetId) | |
52 | 55 | if ((amount > 0)) | |
53 | 56 | then { | |
54 | 57 | let depositInvoke = invoke(proxy, "deposit", nil, [AttachedPayment(asset, amount)]) | |
55 | 58 | if ((depositInvoke == depositInvoke)) | |
56 | 59 | then match depositInvoke { | |
57 | 60 | case receivedStakingAsset: Int => | |
58 | 61 | let newAdditionalBalance = (currentAdditionalBalance + amount) | |
59 | 62 | let newSWavesBalance = (currentStakingAssetBalance + receivedStakingAsset) | |
60 | 63 | [IntegerEntry(keyAdditionalBalance(assetId), newAdditionalBalance), IntegerEntry(keyStakingAssetBalance(stakingAssetId), newSWavesBalance)] | |
61 | 64 | case _ => | |
62 | 65 | nil | |
63 | 66 | } | |
64 | 67 | else throw("Strict value is not equal to itself.") | |
65 | 68 | } | |
66 | 69 | else nil | |
67 | 70 | } | |
68 | 71 | else throw("Strict value is not equal to itself.") | |
69 | 72 | } | |
70 | 73 | else throw("Strict value is not equal to itself.") | |
71 | 74 | } | |
72 | 75 | ||
73 | 76 | ||
74 | 77 | func withdraw (assetId,amount,stakingAssetId,proxy,proxyRateMul) = { | |
75 | 78 | let currentAdditionalBalance = getAdditionalBalance(assetId) | |
76 | 79 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
77 | 80 | then { | |
78 | 81 | let currentStakingAssetBalance = getStakingAssetBalance(stakingAssetId) | |
79 | 82 | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
80 | 83 | then { | |
81 | 84 | let currentProxyRate = getRate(proxy) | |
82 | 85 | if ((currentProxyRate == currentProxyRate)) | |
83 | 86 | then { | |
84 | 87 | let sendStakingAssetAmount = fraction(proxyRateMul, amount, currentProxyRate) | |
85 | 88 | if ((sendStakingAssetAmount > 0)) | |
86 | 89 | then { | |
87 | 90 | let withdrawInvoke = invoke(proxy, "withdraw", nil, [AttachedPayment(fromBase58String(stakingAssetId), sendStakingAssetAmount)]) | |
88 | 91 | if ((withdrawInvoke == withdrawInvoke)) | |
89 | 92 | then match withdrawInvoke { | |
90 | 93 | case receivedAssets: Int => | |
91 | 94 | let newAdditionalBalance = (currentAdditionalBalance - receivedAssets) | |
92 | 95 | let newSWavesBalance = (currentStakingAssetBalance - sendStakingAssetAmount) | |
93 | 96 | [IntegerEntry(keyAdditionalBalance(assetId), newAdditionalBalance), IntegerEntry(keyStakingAssetBalance(stakingAssetId), newSWavesBalance)] | |
94 | 97 | case _ => | |
95 | 98 | nil | |
96 | 99 | } | |
97 | 100 | else throw("Strict value is not equal to itself.") | |
98 | 101 | } | |
99 | 102 | else nil | |
100 | 103 | } | |
101 | 104 | else throw("Strict value is not equal to itself.") | |
102 | 105 | } | |
103 | 106 | else throw("Strict value is not equal to itself.") | |
104 | 107 | } | |
105 | 108 | else throw("Strict value is not equal to itself.") | |
106 | 109 | } | |
107 | 110 | ||
108 | 111 | ||
109 | 112 | func rebalanceInternal (targetRatio,assetId,stakingAssetId,minBalance,proxy,proxyRateMul) = { | |
110 | 113 | let currentAdditionalBalance = getAdditionalBalance(assetId) | |
111 | 114 | if ((currentAdditionalBalance == currentAdditionalBalance)) | |
112 | 115 | then { | |
113 | 116 | let currentStakingAssetBalance = getStakingAssetBalance(stakingAssetId) | |
114 | 117 | if ((currentStakingAssetBalance == currentStakingAssetBalance)) | |
115 | 118 | then { | |
116 | 119 | let availableBalance = if ((assetId == "WAVES")) | |
117 | 120 | then wavesBalance(this).available | |
118 | 121 | else assetBalance(this, fromBase58String(assetId)) | |
119 | 122 | if ((availableBalance == availableBalance)) | |
120 | 123 | then { | |
121 | 124 | let wholeBalance = max([0, ((availableBalance + currentAdditionalBalance) - minBalance)]) | |
122 | 125 | let targetAdditionalBalance = fraction(targetRatio, wholeBalance, 100) | |
123 | 126 | let diff = (currentAdditionalBalance - targetAdditionalBalance) | |
124 | 127 | if ((diff == 0)) | |
125 | 128 | then nil | |
126 | 129 | else if ((0 > diff)) | |
127 | 130 | then { | |
128 | 131 | let sendAssetAmount = -(diff) | |
129 | 132 | deposit(assetId, sendAssetAmount, stakingAssetId, proxy) | |
130 | 133 | } | |
131 | 134 | else { | |
132 | 135 | let getAssetAmount = diff | |
133 | 136 | withdraw(assetId, getAssetAmount, stakingAssetId, proxy, proxyRateMul) | |
134 | 137 | } | |
135 | 138 | } | |
136 | 139 | else throw("Strict value is not equal to itself.") | |
137 | 140 | } | |
138 | 141 | else throw("Strict value is not equal to itself.") | |
139 | 142 | } | |
140 | 143 | else throw("Strict value is not equal to itself.") | |
141 | 144 | } | |
142 | 145 | ||
143 | 146 | ||
144 | 147 | @Callable(i) | |
145 | - | func rebalance () = { | |
146 | - | let asset1 = "WAVES" | |
147 | - | match getLeaseProxyConfig(asset1) { | |
148 | - | case a: (Boolean, Int, Int, String, String, Int, String) => | |
149 | - | let $t042604369 = a | |
150 | - | let isLeasable = $t042604369._1 | |
151 | - | let leasedRatio = $t042604369._2 | |
152 | - | let minBalance = $t042604369._3 | |
153 | - | let proxyAddress = $t042604369._4 | |
154 | - | let proxyAssetId = $t042604369._5 | |
155 | - | let proxyRateMul = $t042604369._6 | |
156 | - | let stakingProfitAddress = $t042604369._7 | |
157 | - | if (isLeasable) | |
158 | - | then rebalanceInternal(leasedRatio, asset1, proxyAssetId, minBalance, addressFromStringValue(proxyAddress), proxyRateMul) | |
159 | - | else nil | |
160 | - | case _ => | |
161 | - | throw("BRR") | |
162 | - | } | |
163 | - | } | |
148 | + | func rebalanceAsset (assetId) = match getLeaseProxyConfig(assetId) { | |
149 | + | case a: (Boolean, Int, Int, String, String, Int, String) => | |
150 | + | let $t043564465 = a | |
151 | + | let isLeasable = $t043564465._1 | |
152 | + | let leasedRatio = $t043564465._2 | |
153 | + | let minBalance = $t043564465._3 | |
154 | + | let proxyAddress = $t043564465._4 | |
155 | + | let proxyAssetId = $t043564465._5 | |
156 | + | let proxyRateMul = $t043564465._6 | |
157 | + | let stakingProfitAddress = $t043564465._7 | |
158 | + | if (isLeasable) | |
159 | + | then rebalanceInternal(leasedRatio, assetId, proxyAssetId, minBalance, addressFromStringValue(proxyAddress), proxyRateMul) | |
160 | + | else nil | |
161 | + | case _ => | |
162 | + | throwError((("[" + assetId) + "] Rebalance error")) | |
163 | + | } | |
164 | 164 | ||
165 | 165 |
github/deemru/w8io/026f985 28.51 ms ◑