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