tx · GpfUgm3QRNNPwSzihyhwWcdLJiYQR9qabTvbjFFym9SW 3MtFPwegkVCnxzhVMLNiXKp7eyk9H2dinxN: -0.10000000 Waves 2022.10.10 16:29 [2266295] smart account 3MtFPwegkVCnxzhVMLNiXKp7eyk9H2dinxN > SELF 0.00000000 Waves
{ "type": 13, "id": "GpfUgm3QRNNPwSzihyhwWcdLJiYQR9qabTvbjFFym9SW", "fee": 10000000, "feeAssetId": null, "timestamp": 1665408532507, "version": 2, "chainId": 84, "sender": "3MtFPwegkVCnxzhVMLNiXKp7eyk9H2dinxN", "senderPublicKey": "RFLKZ4DeMmGzFURw8v6d956tT6ZPkd1a5fZBmY2SFh5", "proofs": [ "2jXrMjvBrrqnQUUqNTLpWK43Rch3KR1gnzYMBCaKT8skZfpLmnc4bnGdYB9zQXiAr9c8Ctcuimw2Dn8gEZKsD4LK", "4LPCZNq1b9AGEmSKBReWcapRtaE4jdYx5ZGuNrznVvnFiTvCZVbhoB2MYsejukBVmZrAbbBs3ZPbgJnrcQrHLNUb" ], "script": "base64:BgIYCAISBAoCCBgSABIAEgUKAwQBCBIDCgEBJgAHa0FjdGl2ZQIGYWN0aXZlAAZrQ2F1c2UCDnNodXRkb3duX2NhdXNlAAxrVVNETkFkZHJlc3MCGHN0YWtpbmdfdXNkbm5zYnRfYWRkcmVzcwAMa0VVUk5BZGRyZXNzAhRzdGFraW5nX2V1cm5fYWRkcmVzcwAMa0xlYXNpbmdQb29sAg9sZWFzaW5nX2FkZHJlc3MADmtMZWFzaW5nQW1vdW50Ag5sZWFzaW5nX2Ftb3VudAAKa0xlYXNpbmdJZAIKbGVhc2luZ19pZAANa0FkbWluUHViS2V5MQILYWRtaW5fcHViXzEADWtBZG1pblB1YktleTICC2FkbWluX3B1Yl8yAA1rQWRtaW5QdWJLZXkzAgthZG1pbl9wdWJfMwASa0FkbWluSW52b2tlUHViS2V5AhBhZG1pbl9pbnZva2VfcHViAA1rQ3BtbUNvbnRyYWN0Ag1jcG1tX2Nv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zCAULJHQwNTk3NzYwODACXzMECHBheW1lbnRzCAULJHQwNTk3NzYwODACXzQEA2ludgkA/AcEBQRhZGRyBQRjYWxsBQZwYXJhbXMFCHBheW1lbnRzAwkAAAIFA2ludgUDaW52BQNuaWwJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4BaQERcmVpc3N1ZVNoYXJlVG9rZW4BBmFtb3VudAkBC3ZhbHVlT3JFbHNlAgkBDmlzR2xvYmFsQ2FsbGVyAQgFAWkGY2FsbGVyCQELdmFsdWVPckVsc2UCCQEIaXNBY3RpdmUABAxzaGFyZUFzc2V0SWQJANkEAQkBEUBleHRyTmF0aXZlKDEwNTMpAgUEdGhpcwUNa1NoYXJlQXNzZXRJZAkAzAgCCQEHUmVpc3N1ZQMFDHNoYXJlQXNzZXRJZAUGYW1vdW50BgkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIFBmFtb3VudAUMc2hhcmVBc3NldElkBQNuaWwBAnR4AQZ2ZXJpZnkABBNtdWx0aVNpZ25lZEJ5QWRtaW5zBBJhZG1pblB1YktleTFTaWduZWQDCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAABQxhZG1pblB1YktleTEAAQAABBJhZG1pblB1YktleTJTaWduZWQDCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwABBQxhZG1pblB1YktleTIAAQAABBJhZG1pblB1YktleTNTaWduZWQDCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwACBQxhZG1pblB1YktleTMAAQAACQBnAgkAZAIJAGQCBRJhZG1pblB1YktleTFTaWduZWQFEmFkbWluUHViS2V5MlNpZ25lZAUSYWRtaW5QdWJLZXkzU2lnbmVkAAIFE211bHRpU2lnbmVkQnlBZG1pbnMIXNbH", "height": 2266295, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: GL165uN2GzFtwZBzUkanZ3ggj16mMLHaj9Ai1uDC6Lcn Next: BaV8Vxk2xSZKtZeApJYGQctNnr7gxzizaZNYQyi7gC7t Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let version = "1.0.0" | |
5 | - | ||
6 | - | let kVersion = "version" | |
7 | - | ||
8 | 4 | let kActive = "active" | |
9 | 5 | ||
10 | - | let kAssetIdA = "A_asset_id" | |
11 | - | ||
12 | - | let kAssetIdB = "B_asset_id" | |
13 | - | ||
14 | - | let kBalanceA = "A_asset_balance" | |
15 | - | ||
16 | - | let kBalanceB = "B_asset_balance" | |
17 | - | ||
18 | - | let kBalanceInitA = "A_asset_init" | |
19 | - | ||
20 | - | let kBalanceInitB = "B_asset_init" | |
21 | - | ||
22 | - | let kShareAssetId = "share_asset_id" | |
23 | - | ||
24 | - | let kShareAssetSupply = "share_asset_supply" | |
25 | - | ||
26 | - | let kFee = "commission" | |
27 | - | ||
28 | 6 | let kCause = "shutdown_cause" | |
29 | - | ||
30 | - | let kFirstHarvest = "first_harvest" | |
31 | - | ||
32 | - | let kFirstHarvestHeight = "first_harvest_height" | |
33 | - | ||
34 | - | let kShareLimit = "share_limit_on_first_harvest" | |
35 | - | ||
36 | - | let kBasePeriod = "base_period" | |
37 | - | ||
38 | - | let kPeriodLength = "period_length" | |
39 | - | ||
40 | - | let kStartHeight = "start_height" | |
41 | 7 | ||
42 | 8 | let kUSDNAddress = "staking_usdnnsbt_address" | |
43 | 9 | ||
49 | 15 | ||
50 | 16 | let kLeasingId = "leasing_id" | |
51 | 17 | ||
52 | - | let kDiscounts = "discounts" | |
53 | - | ||
54 | - | let kDiscountValues = "discount_values" | |
55 | - | ||
56 | - | let kUserSwopInGov = "_SWOP_amount" | |
57 | - | ||
58 | 18 | let kAdminPubKey1 = "admin_pub_1" | |
59 | 19 | ||
60 | 20 | let kAdminPubKey2 = "admin_pub_2" | |
63 | 23 | ||
64 | 24 | let kAdminInvokePubKey = "admin_invoke_pub" | |
65 | 25 | ||
66 | - | let | |
26 | + | let kCpmmContract = "cpmm_contract" | |
67 | 27 | ||
68 | - | let kGovAddress = "governance_address" | |
28 | + | let kUSDNAssetId = "usdn_asset_id" | |
29 | + | ||
30 | + | let kEURNAssetId = "eurn_asset_id" | |
31 | + | ||
32 | + | let kStakingAssets = "staking_assets" | |
33 | + | ||
34 | + | let kShareAssetId = "share_asset_id" | |
69 | 35 | ||
70 | 36 | let oracle = Address(base58'3NBBWfzZtZtszaXbitTKnrB2xXwv26Bn7H9') | |
71 | 37 | ||
83 | 49 | ||
84 | 50 | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
85 | 51 | ||
86 | - | let adminInvokePubKey = getBase58FromOracle(kAdminInvokePubKey) | |
87 | - | ||
88 | - | let moneyBoxAddress = Address(getBase58FromOracle(kMoneyBoxAddress)) | |
89 | - | ||
90 | - | let govAddress = Address(getBase58FromOracle(kGovAddress)) | |
91 | - | ||
92 | - | let votingAddress = Address(base58'3MrJgdL1GniipErHy44YF9idzLaUL2iX5DQ') | |
93 | - | ||
94 | - | let USDN = base58'8UrfDVd5GreeUwm7uPk7eYz1eMv376kzR52C6sANPkwS' | |
95 | - | ||
96 | - | let SWOP = base58'2HAJrwa8q4SxBx9cHYaBTQdBjdk5wwqdof7ccpAx2uhZ' | |
97 | - | ||
98 | - | let EURN = base58'ECBCkHS68DckpBrzLeoRgYbFg7sCVqR176mPqbXsj9pA' | |
99 | - | ||
100 | - | let stakingAssets = ["WAVES", toBase58String(USDN), toBase58String(EURN)] | |
52 | + | let adminPubKeyInvoke = getBase58FromOracle(kAdminInvokePubKey) | |
101 | 53 | ||
102 | 54 | let stakingUSDNAddress = Address(getBase58FromOracle(kUSDNAddress)) | |
103 | 55 | ||
104 | 56 | let stakingEURNAddress = Address(getBase58FromOracle(kEURNAddress)) | |
105 | 57 | ||
106 | - | let | |
58 | + | let cpmmContract = Address(getBase58FromOracle(kCpmmContract)) | |
107 | 59 | ||
108 | - | let | |
60 | + | let USDN = getBase58FromOracle(kUSDNAssetId) | |
109 | 61 | ||
110 | - | let | |
62 | + | let EURN = getBase58FromOracle(kEURNAssetId) | |
111 | 63 | ||
112 | - | let | |
64 | + | let stakingAssets = getStringValue(oracle, kStakingAssets) | |
113 | 65 | ||
114 | - | let active = | |
66 | + | let active = valueOrElse(getBoolean(this, kActive), true) | |
115 | 67 | ||
116 | - | let strAssetIdA = getStringValue(this, kAssetIdA) | |
117 | - | ||
118 | - | let strAssetIdB = getStringValue(this, kAssetIdB) | |
119 | - | ||
120 | - | let assetIdA = if ((strAssetIdA == "WAVES")) | |
68 | + | func isActive () = if (active) | |
121 | 69 | then unit | |
122 | - | else fromBase58String(strAssetIdA) | |
123 | - | ||
124 | - | let assetIdB = if ((strAssetIdB == "WAVES")) | |
125 | - | then unit | |
126 | - | else fromBase58String(strAssetIdB) | |
127 | - | ||
128 | - | let assetNameA = match assetIdA { | |
129 | - | case id: ByteVector => | |
130 | - | value(assetInfo(id)).name | |
131 | - | case waves: Unit => | |
132 | - | "WAVES" | |
133 | - | case _ => | |
134 | - | throw("Match error") | |
135 | - | } | |
136 | - | ||
137 | - | let assetNameB = match assetIdB { | |
138 | - | case id: ByteVector => | |
139 | - | value(assetInfo(id)).name | |
140 | - | case waves: Unit => | |
141 | - | "WAVES" | |
142 | - | case _ => | |
143 | - | throw("Match error") | |
144 | - | } | |
145 | - | ||
146 | - | let balanceA = getIntegerValue(this, kBalanceA) | |
147 | - | ||
148 | - | let balanceB = getIntegerValue(this, kBalanceB) | |
149 | - | ||
150 | - | let shareAssetId = fromBase58String(getStringValue(this, kShareAssetId)) | |
151 | - | ||
152 | - | let shareAssetSupply = getIntegerValue(this, kShareAssetSupply) | |
153 | - | ||
154 | - | let fee = getIntegerValue(this, kFee) | |
155 | - | ||
156 | - | let feeGovernance = fraction(fee, 40, 100) | |
157 | - | ||
158 | - | let feeScale6 = 1000000 | |
159 | - | ||
160 | - | let scaleValue3 = 1000 | |
161 | - | ||
162 | - | let scaleValue8 = 100000000 | |
163 | - | ||
164 | - | let slippageToleranceDelimiter = 1000 | |
165 | - | ||
166 | - | let scaleValue8Digits = 8 | |
167 | - | ||
168 | - | func accountBalance (assetId) = match assetId { | |
169 | - | case id: ByteVector => | |
170 | - | assetBalance(this, id) | |
171 | - | case waves: Unit => | |
172 | - | wavesBalance(this).available | |
173 | - | case _ => | |
174 | - | throw("Match error") | |
175 | - | } | |
70 | + | else throw("DApp is inactive at this moment") | |
176 | 71 | ||
177 | 72 | ||
178 | - | func stakedAmount (assetId) = { | |
179 | - | let stakedAmountCalculated = match assetId { | |
180 | - | case aId: ByteVector => | |
181 | - | if ((aId == USDN)) | |
182 | - | then getInteger(stakingUSDNAddress, ((("rpd_balance_" + toBase58String(aId)) + "_") + toString(this))) | |
183 | - | else if ((aId == EURN)) | |
184 | - | then getInteger(stakingEURNAddress, ((("%s%s%s__stakingBalance__" + toBase58String(aId)) + "__") + toString(this))) | |
185 | - | else 0 | |
186 | - | case _: Unit => | |
187 | - | valueOrElse(getInteger(this, kLeasingAmount), 0) | |
188 | - | case _ => | |
189 | - | throw("Match error") | |
190 | - | } | |
191 | - | match stakedAmountCalculated { | |
192 | - | case i: Int => | |
193 | - | i | |
194 | - | case _ => | |
195 | - | 0 | |
196 | - | } | |
197 | - | } | |
73 | + | func isGlobalCaller (caller) = if ((caller == cpmmContract)) | |
74 | + | then unit | |
75 | + | else throw("Only global Contract can invoke this function") | |
198 | 76 | ||
199 | 77 | ||
200 | - | let stakedAmountA = stakedAmount(assetIdA) | |
201 | - | ||
202 | - | let stakedAmountB = stakedAmount(assetIdB) | |
203 | - | ||
204 | - | let assetInitA = getIntegerValue(this, kBalanceInitA) | |
205 | - | ||
206 | - | let assetInitB = getIntegerValue(this, kBalanceInitB) | |
207 | - | ||
208 | - | let availableBalanceA = (balanceA - stakedAmountA) | |
209 | - | ||
210 | - | let availableBalanceB = (balanceB - stakedAmountB) | |
211 | - | ||
212 | - | let accountBalanceWithStakedA = (accountBalance(assetIdA) + stakedAmountA) | |
213 | - | ||
214 | - | let accountBalanceWithStakedB = (accountBalance(assetIdB) + stakedAmountB) | |
215 | - | ||
216 | - | let hasEnoughBalance = if ((accountBalanceWithStakedA >= balanceA)) | |
217 | - | then (accountBalanceWithStakedB >= balanceB) | |
218 | - | else false | |
219 | - | ||
220 | - | func getAssetInfo (assetId) = match assetId { | |
221 | - | case id: ByteVector => | |
222 | - | let stringId = toBase58String(id) | |
223 | - | let info = valueOrErrorMessage(assetInfo(id), (("Asset " + stringId) + " doesn't exist")) | |
224 | - | $Tuple3(stringId, info.name, info.decimals) | |
225 | - | case waves: Unit => | |
226 | - | $Tuple3("WAVES", "WAVES", 8) | |
227 | - | case _ => | |
228 | - | throw("Match error") | |
229 | - | } | |
230 | - | ||
231 | - | ||
232 | - | func getAssetInfoFromString (assetStr) = if ((assetStr == "WAVES")) | |
233 | - | then $Tuple3("WAVES", "WAVES", 8) | |
234 | - | else { | |
235 | - | let stringId = assetStr | |
236 | - | let id = fromBase58String(assetStr) | |
237 | - | let info = valueOrErrorMessage(assetInfo(id), (("Asset " + stringId) + " doesn't exist")) | |
238 | - | $Tuple3(stringId, info.name, info.decimals) | |
239 | - | } | |
78 | + | func isAdminCall (callerPubKey) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], callerPubKey)) | |
79 | + | then unit | |
80 | + | else throw("Only admin can call this function") | |
240 | 81 | ||
241 | 82 | ||
242 | 83 | func suspend (cause) = [BooleanEntry(kActive, false), StringEntry(kCause, cause)] | |
253 | 94 | ||
254 | 95 | func calcStakingParams (stake,amount,assetId) = if (stake) | |
255 | 96 | then { | |
256 | - | let $ | |
257 | - | let call = $ | |
258 | - | let stakingAddr = $ | |
97 | + | let $t024732539 = calcStakingFuncAndAddres(stake, assetId) | |
98 | + | let call = $t024732539._1 | |
99 | + | let stakingAddr = $t024732539._2 | |
259 | 100 | $Tuple4(call, stakingAddr, nil, [AttachedPayment(assetId, amount)]) | |
260 | 101 | } | |
261 | 102 | else { | |
262 | - | let $ | |
263 | - | let call = $ | |
264 | - | let stakingAddr = $ | |
103 | + | let $t026252691 = calcStakingFuncAndAddres(stake, assetId) | |
104 | + | let call = $t026252691._1 | |
105 | + | let stakingAddr = $t026252691._2 | |
265 | 106 | $Tuple4(call, stakingAddr, [amount, toBase58String(assetId)], nil) | |
266 | 107 | } | |
267 | 108 | ||
268 | 109 | ||
269 | - | func calculateFeeDiscount (userAddr) = { | |
270 | - | let swopAmount = valueOrElse(getInteger(govAddress, (toString(userAddr) + kUserSwopInGov)), 0) | |
271 | - | let discountValues = split(getStringValue(oracle, kDiscountValues), ",") | |
272 | - | let discounts = split(getStringValue(oracle, kDiscounts), ",") | |
273 | - | if (if ((swopAmount >= parseIntValue(discountValues[0]))) | |
274 | - | then (parseIntValue(discountValues[1]) > swopAmount) | |
275 | - | else false) | |
276 | - | then (feeScale6 - parseIntValue(discounts[0])) | |
277 | - | else if (if ((swopAmount >= parseIntValue(discountValues[1]))) | |
278 | - | then (parseIntValue(discountValues[2]) > swopAmount) | |
279 | - | else false) | |
280 | - | then (feeScale6 - parseIntValue(discounts[1])) | |
281 | - | else if (if ((swopAmount >= parseIntValue(discountValues[2]))) | |
282 | - | then (parseIntValue(discountValues[3]) > swopAmount) | |
283 | - | else false) | |
284 | - | then (feeScale6 - parseIntValue(discounts[2])) | |
285 | - | else if (if ((swopAmount >= parseIntValue(discountValues[3]))) | |
286 | - | then (parseIntValue(discountValues[4]) > swopAmount) | |
287 | - | else false) | |
288 | - | then (feeScale6 - parseIntValue(discounts[3])) | |
289 | - | else if ((swopAmount >= parseIntValue(discountValues[4]))) | |
290 | - | then (feeScale6 - parseIntValue(discounts[4])) | |
291 | - | else feeScale6 | |
110 | + | func collectPayments (acc,payment) = { | |
111 | + | let $t028532896 = acc | |
112 | + | let paymentAmounts = $t028532896._1 | |
113 | + | let paymentAssetIds = $t028532896._2 | |
114 | + | $Tuple2((paymentAmounts :+ payment.amount), (paymentAssetIds :+ (if ((payment.assetId == unit)) | |
115 | + | then base58'' | |
116 | + | else payment.assetId))) | |
292 | 117 | } | |
293 | 118 | ||
294 | 119 | ||
295 | - | func calculateFees (pmtAmount,minAmountToReceive,tokenFrom,tokenTo,caller) = { | |
296 | - | let amountWithoutFee = fraction(tokenTo, pmtAmount, (pmtAmount + tokenFrom)) | |
297 | - | let feeDiscount = calculateFeeDiscount(caller) | |
298 | - | let amountWithFee = fraction(amountWithoutFee, (feeScale6 - fraction(fee, feeDiscount, feeScale6, CEILING)), feeScale6) | |
299 | - | let governanceReward = fraction(amountWithoutFee, fraction(feeGovernance, feeDiscount, feeScale6, CEILING), feeScale6) | |
300 | - | if ((minAmountToReceive > amountWithFee)) | |
301 | - | then throw(((("Calculated amount to receive " + toString(amountWithFee)) + " is less than specified minimum ") + toString(minAmountToReceive))) | |
302 | - | else $Tuple3(amountWithoutFee, amountWithFee, governanceReward) | |
303 | - | } | |
120 | + | func collectState (result,source) = match source { | |
121 | + | case e: Issue|Burn|Reissue|ScriptTransfer|BinaryEntry|BooleanEntry|StringEntry|IntegerEntry => | |
122 | + | (result :+ e) | |
123 | + | case _ => | |
124 | + | result | |
125 | + | } | |
304 | 126 | ||
305 | 127 | ||
306 | - | func suspendSuspicious () = suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(accountBalanceWithStakedA)) + " ") + assetNameA) + ", ") + toString(accountBalanceWithStakedB)) + " ") + assetNameB) + ". State: ") + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB)) | |
307 | - | ||
308 | - | ||
309 | - | func isActive () = if (active) | |
310 | - | then unit | |
311 | - | else throw("DApp is inactive at this moment") | |
128 | + | func collectData (result,source) = match source { | |
129 | + | case v: String => | |
130 | + | (result :+ v) | |
131 | + | case v: Int => | |
132 | + | (result :+ v) | |
133 | + | case v: Boolean => | |
134 | + | (result :+ v) | |
135 | + | case v: ByteVector => | |
136 | + | (result :+ v) | |
137 | + | case _ => | |
138 | + | throw() | |
139 | + | } | |
312 | 140 | ||
313 | 141 | ||
314 | 142 | @Callable(i) | |
315 | - | func init (firstHarvest) = { | |
316 | - | let $t088358912 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
317 | - | let pmtAmountA = $t088358912._1 | |
318 | - | let pmtAssetIdA = $t088358912._2 | |
319 | - | let $t089178994 = $Tuple2(i.payments[1].amount, i.payments[1].assetId) | |
320 | - | let pmtAmountB = $t089178994._1 | |
321 | - | let pmtAssetIdB = $t089178994._2 | |
322 | - | let $t089999076 = getAssetInfo(pmtAssetIdA) | |
323 | - | let pmtStrAssetIdA = $t089999076._1 | |
324 | - | let pmtAssetNameA = $t089999076._2 | |
325 | - | let pmtDecimalsA = $t089999076._3 | |
326 | - | let $t090819158 = getAssetInfo(pmtAssetIdB) | |
327 | - | let pmtStrAssetIdB = $t090819158._1 | |
328 | - | let pmtAssetNameB = $t090819158._2 | |
329 | - | let pmtDecimalsB = $t090819158._3 | |
330 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.callerPublicKey))) | |
331 | - | then throw("Only admin can call this function") | |
332 | - | else if (isDefined(getBoolean(this, kActive))) | |
333 | - | then throw("DApp is already active") | |
334 | - | else if ((pmtAssetIdA == pmtAssetIdB)) | |
335 | - | then throw("Assets must be different") | |
336 | - | else { | |
337 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
338 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
339 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
340 | - | let arg1 = pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN) | |
341 | - | let arg2 = pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN) | |
342 | - | let arg3 = pow(10, 0, shareDecimals, 0, 0, DOWN) | |
343 | - | let shareInitialSupply = fraction(arg1, arg2, arg3) | |
344 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
345 | - | let shareIssueId = calculateAssetId(shareIssue) | |
346 | - | let stake1 = if (containsElement(stakingAssets, pmtStrAssetIdA)) | |
347 | - | then invoke(this, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
348 | - | else 0 | |
349 | - | if ((stake1 == stake1)) | |
350 | - | then { | |
351 | - | let stake2 = if (containsElement(stakingAssets, pmtStrAssetIdB)) | |
352 | - | then invoke(this, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
353 | - | else 0 | |
354 | - | if ((stake2 == stake2)) | |
355 | - | then { | |
356 | - | let baseEntry = [StringEntry(kVersion, version), BooleanEntry(kActive, true), StringEntry(kAssetIdA, pmtStrAssetIdA), StringEntry(kAssetIdB, pmtStrAssetIdB), IntegerEntry(kBalanceA, pmtAmountA), IntegerEntry(kBalanceB, pmtAmountB), IntegerEntry(kFee, getIntegerValue(oracle, "base_fee_cpmm")), shareIssue, StringEntry(kShareAssetId, toBase58String(shareIssueId)), IntegerEntry(kShareAssetSupply, shareInitialSupply), ScriptTransfer(i.caller, shareInitialSupply, shareIssueId)] | |
357 | - | if (firstHarvest) | |
358 | - | then (baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]) | |
359 | - | else baseEntry | |
360 | - | } | |
361 | - | else throw("Strict value is not equal to itself.") | |
362 | - | } | |
363 | - | else throw("Strict value is not equal to itself.") | |
364 | - | } | |
365 | - | } | |
143 | + | func callFunction (funcName,args) = valueOrElse(isActive(), { | |
144 | + | let $t037383824 = { | |
145 | + | let $l = i.payments | |
146 | + | let $s = size($l) | |
147 | + | let $acc0 = $Tuple2(nil, nil) | |
148 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
149 | + | then $a | |
150 | + | else collectPayments($a, $l[$i]) | |
366 | 151 | ||
152 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
153 | + | then $a | |
154 | + | else throw("List size exceeds 10") | |
367 | 155 | ||
156 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
157 | + | } | |
158 | + | let paymentAmounts = $t037383824._1 | |
159 | + | let paymentAssetIds = $t037383824._2 | |
160 | + | let $t038273983 = { | |
161 | + | let @ = reentrantInvoke(cpmmContract, funcName, [i.caller.bytes, args, paymentAmounts, paymentAssetIds], nil) | |
162 | + | if ($isInstanceOf(@, "(List[Any], List[Any])")) | |
163 | + | then @ | |
164 | + | else throw(($getType(@) + " couldn't be cast to (List[Any], List[Any])")) | |
165 | + | } | |
166 | + | if (($t038273983 == $t038273983)) | |
167 | + | then { | |
168 | + | let data = $t038273983._2 | |
169 | + | let actions = $t038273983._1 | |
170 | + | let mappedData = { | |
171 | + | let $l = data | |
172 | + | let $s = size($l) | |
173 | + | let $acc0 = nil | |
174 | + | func $f1_1 ($a,$i) = if (($i >= $s)) | |
175 | + | then $a | |
176 | + | else collectData($a, $l[$i]) | |
368 | 177 | ||
369 | - | @Callable(i) | |
370 | - | func initWithInitRatio (amtAssetA,amtAssetB,strAssetIdA,strAssetIdB,firstHarvest) = { | |
371 | - | let $t01166311750 = getAssetInfoFromString(strAssetIdA) | |
372 | - | let pmtStrAssetIdA = $t01166311750._1 | |
373 | - | let pmtAssetNameA = $t01166311750._2 | |
374 | - | let pmtDecimalsA = $t01166311750._3 | |
375 | - | let $t01175511842 = getAssetInfoFromString(strAssetIdB) | |
376 | - | let pmtStrAssetIdB = $t01175511842._1 | |
377 | - | let pmtAssetNameB = $t01175511842._2 | |
378 | - | let pmtDecimalsB = $t01175511842._3 | |
379 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.callerPublicKey))) | |
380 | - | then throw("Only admin can call this function") | |
381 | - | else if (isDefined(getBoolean(this, kActive))) | |
382 | - | then throw("DApp is already active") | |
383 | - | else if ((strAssetIdA == strAssetIdB)) | |
384 | - | then throw("Assets must be different") | |
385 | - | else { | |
386 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
387 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
388 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
389 | - | let shareInitialSupply = 0 | |
390 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
391 | - | let shareIssueId = calculateAssetId(shareIssue) | |
392 | - | let baseEntry = [StringEntry(kVersion, version), BooleanEntry(kActive, true), StringEntry(kAssetIdA, pmtStrAssetIdA), StringEntry(kAssetIdB, pmtStrAssetIdB), IntegerEntry(kBalanceInitA, amtAssetA), IntegerEntry(kBalanceInitB, amtAssetB), IntegerEntry(kBalanceA, 0), IntegerEntry(kBalanceB, 0), IntegerEntry(kFee, getIntegerValue(oracle, "base_fee_cpmm")), shareIssue, StringEntry(kShareAssetId, toBase58String(shareIssueId)), IntegerEntry(kShareAssetSupply, shareInitialSupply)] | |
393 | - | if (firstHarvest) | |
394 | - | then (baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]) | |
395 | - | else baseEntry | |
396 | - | } | |
397 | - | } | |
178 | + | func $f1_2 ($a,$i) = if (($i >= $s)) | |
179 | + | then $a | |
180 | + | else throw("List size exceeds 10") | |
398 | 181 | ||
182 | + | $f1_2($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
183 | + | } | |
184 | + | let mappedActions = { | |
185 | + | let $l = actions | |
186 | + | let $s = size($l) | |
187 | + | let $acc0 = nil | |
188 | + | func $f2_1 ($a,$i) = if (($i >= $s)) | |
189 | + | then $a | |
190 | + | else collectState($a, $l[$i]) | |
399 | 191 | ||
192 | + | func $f2_2 ($a,$i) = if (($i >= $s)) | |
193 | + | then $a | |
194 | + | else throw("List size exceeds 15") | |
400 | 195 | ||
401 | - | @Callable(i) | |
402 | - | func keepLimitForFirstHarvest (shareLimit) = valueOrElse(isActive(), if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.callerPublicKey))) | |
403 | - | then throw("Only admin can call this function") | |
404 | - | else [IntegerEntry(kShareLimit, shareLimit)]) | |
405 | - | ||
406 | - | ||
407 | - | ||
408 | - | @Callable(i) | |
409 | - | func replenishWithTwoTokens (slippageTolerance) = valueOrElse(isActive(), { | |
410 | - | let pmtAssetIdA = i.payments[0].assetId | |
411 | - | let pmtAssetIdB = i.payments[1].assetId | |
412 | - | let pmtAmountA = i.payments[0].amount | |
413 | - | let pmtAmountB = i.payments[1].amount | |
414 | - | let $t01422114298 = getAssetInfo(pmtAssetIdA) | |
415 | - | let pmtStrAssetIdA = $t01422114298._1 | |
416 | - | let pmtAssetNameA = $t01422114298._2 | |
417 | - | let pmtDecimalsA = $t01422114298._3 | |
418 | - | let $t01430314380 = getAssetInfo(pmtAssetIdB) | |
419 | - | let pmtStrAssetIdB = $t01430314380._1 | |
420 | - | let pmtAssetNameB = $t01430314380._2 | |
421 | - | let pmtDecimalsB = $t01430314380._3 | |
422 | - | let inital = if (if ((balanceA == 0)) | |
423 | - | then (balanceB == 0) | |
424 | - | else false) | |
425 | - | then true | |
426 | - | else false | |
427 | - | let tokenRatio = if (inital) | |
428 | - | then fraction(fraction(assetInitA, scaleValue8, pmtAmountA), scaleValue3, fraction(assetInitB, scaleValue8, pmtAmountB)) | |
429 | - | else fraction(fraction(balanceA, scaleValue8, pmtAmountA), scaleValue3, fraction(balanceB, scaleValue8, pmtAmountB)) | |
430 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
431 | - | let shareTokenToPayAmount = if (inital) | |
432 | - | then fraction(pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN), pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN), pow(10, 0, shareDecimals, 0, 0, DOWN)) | |
433 | - | else fraction(min([fraction(pmtAmountA, scaleValue8, balanceA), fraction(pmtAmountB, scaleValue8, balanceB)]), shareAssetSupply, scaleValue8) | |
434 | - | if (if ((0 > slippageTolerance)) | |
435 | - | then true | |
436 | - | else (slippageTolerance > slippageToleranceDelimiter)) | |
437 | - | then throw(((("Slippage tolerance must be between 0 and " + toString(slippageToleranceDelimiter)) + " inclusively. Actual: ") + toString(slippageTolerance))) | |
438 | - | else if ((size(i.payments) != 2)) | |
439 | - | then throw("Two attached assets expected") | |
440 | - | else if (if ((pmtAssetIdA != assetIdA)) | |
441 | - | then true | |
442 | - | else (pmtAssetIdB != assetIdB)) | |
443 | - | then throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
444 | - | else if (if ((((scaleValue3 * (slippageToleranceDelimiter - slippageTolerance)) / slippageToleranceDelimiter) > tokenRatio)) | |
445 | - | then true | |
446 | - | else (tokenRatio > ((scaleValue3 * (slippageToleranceDelimiter + slippageTolerance)) / slippageToleranceDelimiter))) | |
447 | - | then throw("Incorrect assets amount: amounts must have the contract ratio") | |
448 | - | else if ((shareTokenToPayAmount == 0)) | |
449 | - | then throw("Too small amount to replenish") | |
450 | - | else if (!(hasEnoughBalance)) | |
451 | - | then ([ScriptTransfer(i.caller, pmtAmountA, pmtAssetIdA), ScriptTransfer(i.caller, pmtAmountB, pmtAssetIdB)] ++ suspendSuspicious()) | |
452 | - | else { | |
453 | - | let stake1 = if (containsElement(stakingAssets, pmtStrAssetIdA)) | |
454 | - | then invoke(this, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
455 | - | else 0 | |
456 | - | if ((stake1 == stake1)) | |
457 | - | then { | |
458 | - | let stake2 = if (containsElement(stakingAssets, pmtStrAssetIdB)) | |
459 | - | then invoke(this, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
460 | - | else 0 | |
461 | - | if ((stake2 == stake2)) | |
462 | - | then [Reissue(shareAssetId, shareTokenToPayAmount, true), IntegerEntry(kBalanceA, (balanceA + pmtAmountA)), IntegerEntry(kBalanceB, (balanceB + pmtAmountB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId)] | |
463 | - | else throw("Strict value is not equal to itself.") | |
464 | - | } | |
465 | - | else throw("Strict value is not equal to itself.") | |
466 | - | } | |
196 | + | $f2_2($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
197 | + | } | |
198 | + | $Tuple2(mappedActions, mappedData) | |
199 | + | } | |
200 | + | else throw("Strict value is not equal to itself.") | |
467 | 201 | }) | |
468 | 202 | ||
469 | 203 | ||
470 | 204 | ||
471 | 205 | @Callable(i) | |
472 | - | func withdraw () = valueOrElse(isActive(), { | |
473 | - | let $t01718017255 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
474 | - | let pmtAmount = $t01718017255._1 | |
475 | - | let pmtAssetId = $t01718017255._2 | |
476 | - | let amountToPayA = fraction(pmtAmount, balanceA, shareAssetSupply) | |
477 | - | let amountToPayB = fraction(pmtAmount, balanceB, shareAssetSupply) | |
478 | - | if ((size(i.payments) != 1)) | |
479 | - | then throw("One attached payment expected") | |
480 | - | else if ((pmtAssetId != shareAssetId)) | |
481 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
482 | - | else if (!(hasEnoughBalance)) | |
483 | - | then ([ScriptTransfer(i.caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious()) | |
484 | - | else { | |
485 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
486 | - | then invoke(this, "stakeUnstake", [false, amountToPayA, strAssetIdA], nil) | |
487 | - | else 0 | |
488 | - | if ((stake1 == stake1)) | |
489 | - | then { | |
490 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
491 | - | then invoke(this, "stakeUnstake", [false, amountToPayB, strAssetIdB], nil) | |
492 | - | else 0 | |
493 | - | if ((stake2 == stake2)) | |
494 | - | then [IntegerEntry(kBalanceA, (balanceA - amountToPayA)), IntegerEntry(kBalanceB, (balanceB - amountToPayB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply - pmtAmount)), Burn(shareAssetId, pmtAmount), ScriptTransfer(i.caller, amountToPayA, assetIdA), ScriptTransfer(i.caller, amountToPayB, assetIdB)] | |
495 | - | else throw("Strict value is not equal to itself.") | |
496 | - | } | |
497 | - | else throw("Strict value is not equal to itself.") | |
498 | - | } | |
499 | - | }) | |
206 | + | func shutdown () = valueOrElse(isAdminCall(i.callerPublicKey), if (!(active)) | |
207 | + | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, kCause), "the cause wasn't specified"))) | |
208 | + | else suspend("Paused by admin")) | |
500 | 209 | ||
501 | 210 | ||
502 | 211 | ||
503 | 212 | @Callable(i) | |
504 | - | func exchange (minAmountToReceive) = valueOrElse(isActive(), { | |
505 | - | let $t01855418629 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
506 | - | let pmtAmount = $t01855418629._1 | |
507 | - | let pmtAssetId = $t01855418629._2 | |
508 | - | if (if ((balanceA == 0)) | |
509 | - | then true | |
510 | - | else (balanceB == 0)) | |
511 | - | then throw("Can't exchange with zero balance") | |
512 | - | else if ((0 >= minAmountToReceive)) | |
513 | - | then throw(("Minimal amount to receive must be positive. Actual: " + toString(minAmountToReceive))) | |
514 | - | else if ((size(i.payments) != 1)) | |
515 | - | then throw("One attached payment expected") | |
516 | - | else if (!(hasEnoughBalance)) | |
517 | - | then ([ScriptTransfer(i.caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious()) | |
518 | - | else if ((pmtAssetId == assetIdA)) | |
519 | - | then { | |
520 | - | let assetIdSend = assetIdB | |
521 | - | let $t01918019318 = calculateFees(pmtAmount, minAmountToReceive, balanceA, balanceB, i.originCaller) | |
522 | - | let amountWithoutFee = $t01918019318._1 | |
523 | - | let amountWithFee = $t01918019318._2 | |
524 | - | let governanceReward = $t01918019318._3 | |
525 | - | let newBalanceA = (balanceA + pmtAmount) | |
526 | - | let newBalanceB = ((balanceB - amountWithFee) - governanceReward) | |
527 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
528 | - | then invoke(this, "stakeUnstake", [true, pmtAmount, strAssetIdA], nil) | |
529 | - | else 0 | |
530 | - | if ((stake1 == stake1)) | |
531 | - | then { | |
532 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
533 | - | then invoke(this, "stakeUnstake", [false, (amountWithFee + governanceReward), strAssetIdB], nil) | |
534 | - | else 0 | |
535 | - | if ((stake2 == stake2)) | |
536 | - | then $Tuple2([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(moneyBoxAddress, governanceReward, assetIdSend)], $Tuple2(amountWithFee, assetIdSend)) | |
537 | - | else throw("Strict value is not equal to itself.") | |
538 | - | } | |
539 | - | else throw("Strict value is not equal to itself.") | |
540 | - | } | |
541 | - | else if ((pmtAssetId == assetIdB)) | |
542 | - | then { | |
543 | - | let assetIdSend = assetIdA | |
544 | - | let $t02031020448 = calculateFees(pmtAmount, minAmountToReceive, balanceB, balanceA, i.originCaller) | |
545 | - | let amountWithoutFee = $t02031020448._1 | |
546 | - | let amountWithFee = $t02031020448._2 | |
547 | - | let governanceReward = $t02031020448._3 | |
548 | - | let newBalanceA = ((balanceA - amountWithFee) - governanceReward) | |
549 | - | let newBalanceB = (balanceB + pmtAmount) | |
550 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
551 | - | then invoke(this, "stakeUnstake", [false, (amountWithFee + governanceReward), strAssetIdA], nil) | |
552 | - | else 0 | |
553 | - | if ((stake1 == stake1)) | |
554 | - | then { | |
555 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
556 | - | then invoke(this, "stakeUnstake", [true, pmtAmount, strAssetIdB], nil) | |
557 | - | else 0 | |
558 | - | if ((stake2 == stake2)) | |
559 | - | then $Tuple2([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(moneyBoxAddress, governanceReward, assetIdSend)], $Tuple2(amountWithFee, assetIdSend)) | |
560 | - | else throw("Strict value is not equal to itself.") | |
561 | - | } | |
562 | - | else throw("Strict value is not equal to itself.") | |
563 | - | } | |
564 | - | else throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
565 | - | }) | |
213 | + | func activate () = valueOrElse(isAdminCall(i.callerPublicKey), if (active) | |
214 | + | then throw("DApp is already active") | |
215 | + | else [BooleanEntry(kActive, true), DeleteEntry(kCause)]) | |
566 | 216 | ||
567 | 217 | ||
568 | 218 | ||
569 | 219 | @Callable(i) | |
570 | - | func shutdown () = if (!(active)) | |
571 | - | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, kCause), "the cause wasn't specified"))) | |
572 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
573 | - | then throw("Only admin can call this function") | |
574 | - | else suspend("Paused by admin") | |
575 | - | ||
576 | - | ||
577 | - | ||
578 | - | @Callable(i) | |
579 | - | func activate () = if (active) | |
580 | - | then throw("DApp is already active") | |
581 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
582 | - | then throw("Only admin can call this function") | |
583 | - | else [BooleanEntry(kActive, true), DeleteEntry(kCause)] | |
584 | - | ||
585 | - | ||
586 | - | ||
587 | - | @Callable(i) | |
588 | - | func takeIntoAccountExtraFunds () = valueOrElse(isActive(), { | |
589 | - | let amountEnrollA = (accountBalanceWithStakedA - balanceA) | |
590 | - | let amountEnrollB = (accountBalanceWithStakedB - balanceB) | |
591 | - | if ((i.caller != moneyBoxAddress)) | |
592 | - | then throw("Only the wallet can call this function") | |
593 | - | else if (if ((0 > amountEnrollA)) | |
594 | - | then true | |
595 | - | else (0 > amountEnrollB)) | |
596 | - | then suspend("Enroll amount negative") | |
597 | - | else if (if ((amountEnrollA == 0)) | |
598 | - | then (amountEnrollB == 0) | |
599 | - | else false) | |
600 | - | then throw("No money to take") | |
601 | - | else { | |
602 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
603 | - | then invoke(this, "stakeUnstake", [true, amountEnrollA, strAssetIdA], nil) | |
604 | - | else 0 | |
605 | - | if ((stake1 == stake1)) | |
606 | - | then { | |
607 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
608 | - | then invoke(this, "stakeUnstake", [true, amountEnrollB, strAssetIdB], nil) | |
609 | - | else 0 | |
610 | - | if ((stake2 == stake2)) | |
611 | - | then [IntegerEntry(kBalanceA, (balanceA + amountEnrollA)), IntegerEntry(kBalanceB, (balanceB + amountEnrollB)), IntegerEntry(("last_income_" + strAssetIdA), amountEnrollA), IntegerEntry(("last_income_" + strAssetIdB), amountEnrollB)] | |
612 | - | else throw("Strict value is not equal to itself.") | |
613 | - | } | |
614 | - | else throw("Strict value is not equal to itself.") | |
615 | - | } | |
616 | - | }) | |
617 | - | ||
618 | - | ||
619 | - | ||
620 | - | @Callable(i) | |
621 | - | func stakeUnstake (stake,amount,assetIdString) = if ((i.caller != this)) | |
622 | - | then throw("Only contract itself can invoke this function") | |
220 | + | func stakeUnstake (stake,amount,assetIdString) = valueOrElse(isGlobalCaller(i.caller), valueOrElse(isActive(), if ((i.caller != cpmmContract)) | |
221 | + | then throw("Only global Contract can invoke this function") | |
623 | 222 | else if ((assetIdString == "WAVES")) | |
624 | 223 | then { | |
625 | 224 | let pool = addressFromStringValue(valueOrErrorMessage(getString(oracle, kLeasingPool), "No leasing pool in oracle")) | |
639 | 238 | } | |
640 | 239 | } | |
641 | 240 | else { | |
642 | - | let $ | |
643 | - | let call = $ | |
644 | - | let addr = $ | |
645 | - | let params = $ | |
646 | - | let payments = $ | |
241 | + | let $t059776080 = calcStakingParams(stake, amount, fromBase58String(assetIdString)) | |
242 | + | let call = $t059776080._1 | |
243 | + | let addr = $t059776080._2 | |
244 | + | let params = $t059776080._3 | |
245 | + | let payments = $t059776080._4 | |
647 | 246 | let inv = invoke(addr, call, params, payments) | |
648 | 247 | if ((inv == inv)) | |
649 | 248 | then nil | |
650 | 249 | else throw("Strict value is not equal to itself.") | |
651 | - | } | |
250 | + | })) | |
652 | 251 | ||
653 | 252 | ||
654 | 253 | ||
655 | 254 | @Callable(i) | |
656 | - | func stakeAll () = valueOrElse(isActive(), if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
657 | - | then throw("Only admin can call this function") | |
658 | - | else { | |
659 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
660 | - | then { | |
661 | - | let amountA = (balanceA - stakedAmountA) | |
662 | - | if ((amountA > 0)) | |
663 | - | then invoke(this, "stakeUnstake", [true, amountA, strAssetIdA], nil) | |
664 | - | else 0 | |
665 | - | } | |
666 | - | else 0 | |
667 | - | if ((stake1 == stake1)) | |
668 | - | then { | |
669 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
670 | - | then { | |
671 | - | let amountB = (balanceB - stakedAmountB) | |
672 | - | if ((amountB > 0)) | |
673 | - | then invoke(this, "stakeUnstake", [true, amountB, strAssetIdB], nil) | |
674 | - | else 0 | |
675 | - | } | |
676 | - | else 0 | |
677 | - | if ((stake2 == stake2)) | |
678 | - | then nil | |
679 | - | else throw("Strict value is not equal to itself.") | |
680 | - | } | |
681 | - | else throw("Strict value is not equal to itself.") | |
682 | - | }) | |
255 | + | func reissueShareToken (amount) = valueOrElse(isGlobalCaller(i.caller), valueOrElse(isActive(), { | |
256 | + | let shareAssetId = fromBase58String(getStringValue(this, kShareAssetId)) | |
257 | + | [Reissue(shareAssetId, amount, true), ScriptTransfer(i.caller, amount, shareAssetId)] | |
258 | + | })) | |
683 | 259 | ||
684 | 260 | ||
685 | 261 | @Verifier(tx) | |
696 | 272 | else 0 | |
697 | 273 | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
698 | 274 | } | |
699 | - | match tx { | |
700 | - | case inv: InvokeScriptTransaction => | |
701 | - | let callTakeIntoAccount = if ((inv.dApp == this)) | |
702 | - | then (inv.function == "takeIntoAccountExtraFunds") | |
703 | - | else false | |
704 | - | let signedByAdmin = if (if (if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
705 | - | then true | |
706 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey2)) | |
707 | - | then true | |
708 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey3)) | |
709 | - | then true | |
710 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], adminInvokePubKey) | |
711 | - | if (if (callTakeIntoAccount) | |
712 | - | then signedByAdmin | |
713 | - | else false) | |
714 | - | then true | |
715 | - | else multiSignedByAdmins | |
716 | - | case _ => | |
717 | - | multiSignedByAdmins | |
718 | - | } | |
275 | + | multiSignedByAdmins | |
719 | 276 | } | |
720 | 277 |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let version = "1.0.0" | |
5 | - | ||
6 | - | let kVersion = "version" | |
7 | - | ||
8 | 4 | let kActive = "active" | |
9 | 5 | ||
10 | - | let kAssetIdA = "A_asset_id" | |
11 | - | ||
12 | - | let kAssetIdB = "B_asset_id" | |
13 | - | ||
14 | - | let kBalanceA = "A_asset_balance" | |
15 | - | ||
16 | - | let kBalanceB = "B_asset_balance" | |
17 | - | ||
18 | - | let kBalanceInitA = "A_asset_init" | |
19 | - | ||
20 | - | let kBalanceInitB = "B_asset_init" | |
21 | - | ||
22 | - | let kShareAssetId = "share_asset_id" | |
23 | - | ||
24 | - | let kShareAssetSupply = "share_asset_supply" | |
25 | - | ||
26 | - | let kFee = "commission" | |
27 | - | ||
28 | 6 | let kCause = "shutdown_cause" | |
29 | - | ||
30 | - | let kFirstHarvest = "first_harvest" | |
31 | - | ||
32 | - | let kFirstHarvestHeight = "first_harvest_height" | |
33 | - | ||
34 | - | let kShareLimit = "share_limit_on_first_harvest" | |
35 | - | ||
36 | - | let kBasePeriod = "base_period" | |
37 | - | ||
38 | - | let kPeriodLength = "period_length" | |
39 | - | ||
40 | - | let kStartHeight = "start_height" | |
41 | 7 | ||
42 | 8 | let kUSDNAddress = "staking_usdnnsbt_address" | |
43 | 9 | ||
44 | 10 | let kEURNAddress = "staking_eurn_address" | |
45 | 11 | ||
46 | 12 | let kLeasingPool = "leasing_address" | |
47 | 13 | ||
48 | 14 | let kLeasingAmount = "leasing_amount" | |
49 | 15 | ||
50 | 16 | let kLeasingId = "leasing_id" | |
51 | 17 | ||
52 | - | let kDiscounts = "discounts" | |
53 | - | ||
54 | - | let kDiscountValues = "discount_values" | |
55 | - | ||
56 | - | let kUserSwopInGov = "_SWOP_amount" | |
57 | - | ||
58 | 18 | let kAdminPubKey1 = "admin_pub_1" | |
59 | 19 | ||
60 | 20 | let kAdminPubKey2 = "admin_pub_2" | |
61 | 21 | ||
62 | 22 | let kAdminPubKey3 = "admin_pub_3" | |
63 | 23 | ||
64 | 24 | let kAdminInvokePubKey = "admin_invoke_pub" | |
65 | 25 | ||
66 | - | let | |
26 | + | let kCpmmContract = "cpmm_contract" | |
67 | 27 | ||
68 | - | let kGovAddress = "governance_address" | |
28 | + | let kUSDNAssetId = "usdn_asset_id" | |
29 | + | ||
30 | + | let kEURNAssetId = "eurn_asset_id" | |
31 | + | ||
32 | + | let kStakingAssets = "staking_assets" | |
33 | + | ||
34 | + | let kShareAssetId = "share_asset_id" | |
69 | 35 | ||
70 | 36 | let oracle = Address(base58'3NBBWfzZtZtszaXbitTKnrB2xXwv26Bn7H9') | |
71 | 37 | ||
72 | 38 | func getBase58FromOracle (key) = match getString(oracle, key) { | |
73 | 39 | case string: String => | |
74 | 40 | fromBase58String(string) | |
75 | 41 | case nothing => | |
76 | 42 | throw((key + "is empty")) | |
77 | 43 | } | |
78 | 44 | ||
79 | 45 | ||
80 | 46 | let adminPubKey1 = getBase58FromOracle(kAdminPubKey1) | |
81 | 47 | ||
82 | 48 | let adminPubKey2 = getBase58FromOracle(kAdminPubKey2) | |
83 | 49 | ||
84 | 50 | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
85 | 51 | ||
86 | - | let adminInvokePubKey = getBase58FromOracle(kAdminInvokePubKey) | |
87 | - | ||
88 | - | let moneyBoxAddress = Address(getBase58FromOracle(kMoneyBoxAddress)) | |
89 | - | ||
90 | - | let govAddress = Address(getBase58FromOracle(kGovAddress)) | |
91 | - | ||
92 | - | let votingAddress = Address(base58'3MrJgdL1GniipErHy44YF9idzLaUL2iX5DQ') | |
93 | - | ||
94 | - | let USDN = base58'8UrfDVd5GreeUwm7uPk7eYz1eMv376kzR52C6sANPkwS' | |
95 | - | ||
96 | - | let SWOP = base58'2HAJrwa8q4SxBx9cHYaBTQdBjdk5wwqdof7ccpAx2uhZ' | |
97 | - | ||
98 | - | let EURN = base58'ECBCkHS68DckpBrzLeoRgYbFg7sCVqR176mPqbXsj9pA' | |
99 | - | ||
100 | - | let stakingAssets = ["WAVES", toBase58String(USDN), toBase58String(EURN)] | |
52 | + | let adminPubKeyInvoke = getBase58FromOracle(kAdminInvokePubKey) | |
101 | 53 | ||
102 | 54 | let stakingUSDNAddress = Address(getBase58FromOracle(kUSDNAddress)) | |
103 | 55 | ||
104 | 56 | let stakingEURNAddress = Address(getBase58FromOracle(kEURNAddress)) | |
105 | 57 | ||
106 | - | let | |
58 | + | let cpmmContract = Address(getBase58FromOracle(kCpmmContract)) | |
107 | 59 | ||
108 | - | let | |
60 | + | let USDN = getBase58FromOracle(kUSDNAssetId) | |
109 | 61 | ||
110 | - | let | |
62 | + | let EURN = getBase58FromOracle(kEURNAssetId) | |
111 | 63 | ||
112 | - | let | |
64 | + | let stakingAssets = getStringValue(oracle, kStakingAssets) | |
113 | 65 | ||
114 | - | let active = | |
66 | + | let active = valueOrElse(getBoolean(this, kActive), true) | |
115 | 67 | ||
116 | - | let strAssetIdA = getStringValue(this, kAssetIdA) | |
117 | - | ||
118 | - | let strAssetIdB = getStringValue(this, kAssetIdB) | |
119 | - | ||
120 | - | let assetIdA = if ((strAssetIdA == "WAVES")) | |
68 | + | func isActive () = if (active) | |
121 | 69 | then unit | |
122 | - | else fromBase58String(strAssetIdA) | |
123 | - | ||
124 | - | let assetIdB = if ((strAssetIdB == "WAVES")) | |
125 | - | then unit | |
126 | - | else fromBase58String(strAssetIdB) | |
127 | - | ||
128 | - | let assetNameA = match assetIdA { | |
129 | - | case id: ByteVector => | |
130 | - | value(assetInfo(id)).name | |
131 | - | case waves: Unit => | |
132 | - | "WAVES" | |
133 | - | case _ => | |
134 | - | throw("Match error") | |
135 | - | } | |
136 | - | ||
137 | - | let assetNameB = match assetIdB { | |
138 | - | case id: ByteVector => | |
139 | - | value(assetInfo(id)).name | |
140 | - | case waves: Unit => | |
141 | - | "WAVES" | |
142 | - | case _ => | |
143 | - | throw("Match error") | |
144 | - | } | |
145 | - | ||
146 | - | let balanceA = getIntegerValue(this, kBalanceA) | |
147 | - | ||
148 | - | let balanceB = getIntegerValue(this, kBalanceB) | |
149 | - | ||
150 | - | let shareAssetId = fromBase58String(getStringValue(this, kShareAssetId)) | |
151 | - | ||
152 | - | let shareAssetSupply = getIntegerValue(this, kShareAssetSupply) | |
153 | - | ||
154 | - | let fee = getIntegerValue(this, kFee) | |
155 | - | ||
156 | - | let feeGovernance = fraction(fee, 40, 100) | |
157 | - | ||
158 | - | let feeScale6 = 1000000 | |
159 | - | ||
160 | - | let scaleValue3 = 1000 | |
161 | - | ||
162 | - | let scaleValue8 = 100000000 | |
163 | - | ||
164 | - | let slippageToleranceDelimiter = 1000 | |
165 | - | ||
166 | - | let scaleValue8Digits = 8 | |
167 | - | ||
168 | - | func accountBalance (assetId) = match assetId { | |
169 | - | case id: ByteVector => | |
170 | - | assetBalance(this, id) | |
171 | - | case waves: Unit => | |
172 | - | wavesBalance(this).available | |
173 | - | case _ => | |
174 | - | throw("Match error") | |
175 | - | } | |
70 | + | else throw("DApp is inactive at this moment") | |
176 | 71 | ||
177 | 72 | ||
178 | - | func stakedAmount (assetId) = { | |
179 | - | let stakedAmountCalculated = match assetId { | |
180 | - | case aId: ByteVector => | |
181 | - | if ((aId == USDN)) | |
182 | - | then getInteger(stakingUSDNAddress, ((("rpd_balance_" + toBase58String(aId)) + "_") + toString(this))) | |
183 | - | else if ((aId == EURN)) | |
184 | - | then getInteger(stakingEURNAddress, ((("%s%s%s__stakingBalance__" + toBase58String(aId)) + "__") + toString(this))) | |
185 | - | else 0 | |
186 | - | case _: Unit => | |
187 | - | valueOrElse(getInteger(this, kLeasingAmount), 0) | |
188 | - | case _ => | |
189 | - | throw("Match error") | |
190 | - | } | |
191 | - | match stakedAmountCalculated { | |
192 | - | case i: Int => | |
193 | - | i | |
194 | - | case _ => | |
195 | - | 0 | |
196 | - | } | |
197 | - | } | |
73 | + | func isGlobalCaller (caller) = if ((caller == cpmmContract)) | |
74 | + | then unit | |
75 | + | else throw("Only global Contract can invoke this function") | |
198 | 76 | ||
199 | 77 | ||
200 | - | let stakedAmountA = stakedAmount(assetIdA) | |
201 | - | ||
202 | - | let stakedAmountB = stakedAmount(assetIdB) | |
203 | - | ||
204 | - | let assetInitA = getIntegerValue(this, kBalanceInitA) | |
205 | - | ||
206 | - | let assetInitB = getIntegerValue(this, kBalanceInitB) | |
207 | - | ||
208 | - | let availableBalanceA = (balanceA - stakedAmountA) | |
209 | - | ||
210 | - | let availableBalanceB = (balanceB - stakedAmountB) | |
211 | - | ||
212 | - | let accountBalanceWithStakedA = (accountBalance(assetIdA) + stakedAmountA) | |
213 | - | ||
214 | - | let accountBalanceWithStakedB = (accountBalance(assetIdB) + stakedAmountB) | |
215 | - | ||
216 | - | let hasEnoughBalance = if ((accountBalanceWithStakedA >= balanceA)) | |
217 | - | then (accountBalanceWithStakedB >= balanceB) | |
218 | - | else false | |
219 | - | ||
220 | - | func getAssetInfo (assetId) = match assetId { | |
221 | - | case id: ByteVector => | |
222 | - | let stringId = toBase58String(id) | |
223 | - | let info = valueOrErrorMessage(assetInfo(id), (("Asset " + stringId) + " doesn't exist")) | |
224 | - | $Tuple3(stringId, info.name, info.decimals) | |
225 | - | case waves: Unit => | |
226 | - | $Tuple3("WAVES", "WAVES", 8) | |
227 | - | case _ => | |
228 | - | throw("Match error") | |
229 | - | } | |
230 | - | ||
231 | - | ||
232 | - | func getAssetInfoFromString (assetStr) = if ((assetStr == "WAVES")) | |
233 | - | then $Tuple3("WAVES", "WAVES", 8) | |
234 | - | else { | |
235 | - | let stringId = assetStr | |
236 | - | let id = fromBase58String(assetStr) | |
237 | - | let info = valueOrErrorMessage(assetInfo(id), (("Asset " + stringId) + " doesn't exist")) | |
238 | - | $Tuple3(stringId, info.name, info.decimals) | |
239 | - | } | |
78 | + | func isAdminCall (callerPubKey) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], callerPubKey)) | |
79 | + | then unit | |
80 | + | else throw("Only admin can call this function") | |
240 | 81 | ||
241 | 82 | ||
242 | 83 | func suspend (cause) = [BooleanEntry(kActive, false), StringEntry(kCause, cause)] | |
243 | 84 | ||
244 | 85 | ||
245 | 86 | func calcStakingFuncAndAddres (stake,assetId) = if (stake) | |
246 | 87 | then if ((assetId == USDN)) | |
247 | 88 | then $Tuple2("lockNeutrino", stakingUSDNAddress) | |
248 | 89 | else $Tuple2("startStaking", stakingEURNAddress) | |
249 | 90 | else if ((assetId == USDN)) | |
250 | 91 | then $Tuple2("unlockNeutrino", stakingUSDNAddress) | |
251 | 92 | else $Tuple2("stopStaking", stakingEURNAddress) | |
252 | 93 | ||
253 | 94 | ||
254 | 95 | func calcStakingParams (stake,amount,assetId) = if (stake) | |
255 | 96 | then { | |
256 | - | let $ | |
257 | - | let call = $ | |
258 | - | let stakingAddr = $ | |
97 | + | let $t024732539 = calcStakingFuncAndAddres(stake, assetId) | |
98 | + | let call = $t024732539._1 | |
99 | + | let stakingAddr = $t024732539._2 | |
259 | 100 | $Tuple4(call, stakingAddr, nil, [AttachedPayment(assetId, amount)]) | |
260 | 101 | } | |
261 | 102 | else { | |
262 | - | let $ | |
263 | - | let call = $ | |
264 | - | let stakingAddr = $ | |
103 | + | let $t026252691 = calcStakingFuncAndAddres(stake, assetId) | |
104 | + | let call = $t026252691._1 | |
105 | + | let stakingAddr = $t026252691._2 | |
265 | 106 | $Tuple4(call, stakingAddr, [amount, toBase58String(assetId)], nil) | |
266 | 107 | } | |
267 | 108 | ||
268 | 109 | ||
269 | - | func calculateFeeDiscount (userAddr) = { | |
270 | - | let swopAmount = valueOrElse(getInteger(govAddress, (toString(userAddr) + kUserSwopInGov)), 0) | |
271 | - | let discountValues = split(getStringValue(oracle, kDiscountValues), ",") | |
272 | - | let discounts = split(getStringValue(oracle, kDiscounts), ",") | |
273 | - | if (if ((swopAmount >= parseIntValue(discountValues[0]))) | |
274 | - | then (parseIntValue(discountValues[1]) > swopAmount) | |
275 | - | else false) | |
276 | - | then (feeScale6 - parseIntValue(discounts[0])) | |
277 | - | else if (if ((swopAmount >= parseIntValue(discountValues[1]))) | |
278 | - | then (parseIntValue(discountValues[2]) > swopAmount) | |
279 | - | else false) | |
280 | - | then (feeScale6 - parseIntValue(discounts[1])) | |
281 | - | else if (if ((swopAmount >= parseIntValue(discountValues[2]))) | |
282 | - | then (parseIntValue(discountValues[3]) > swopAmount) | |
283 | - | else false) | |
284 | - | then (feeScale6 - parseIntValue(discounts[2])) | |
285 | - | else if (if ((swopAmount >= parseIntValue(discountValues[3]))) | |
286 | - | then (parseIntValue(discountValues[4]) > swopAmount) | |
287 | - | else false) | |
288 | - | then (feeScale6 - parseIntValue(discounts[3])) | |
289 | - | else if ((swopAmount >= parseIntValue(discountValues[4]))) | |
290 | - | then (feeScale6 - parseIntValue(discounts[4])) | |
291 | - | else feeScale6 | |
110 | + | func collectPayments (acc,payment) = { | |
111 | + | let $t028532896 = acc | |
112 | + | let paymentAmounts = $t028532896._1 | |
113 | + | let paymentAssetIds = $t028532896._2 | |
114 | + | $Tuple2((paymentAmounts :+ payment.amount), (paymentAssetIds :+ (if ((payment.assetId == unit)) | |
115 | + | then base58'' | |
116 | + | else payment.assetId))) | |
292 | 117 | } | |
293 | 118 | ||
294 | 119 | ||
295 | - | func calculateFees (pmtAmount,minAmountToReceive,tokenFrom,tokenTo,caller) = { | |
296 | - | let amountWithoutFee = fraction(tokenTo, pmtAmount, (pmtAmount + tokenFrom)) | |
297 | - | let feeDiscount = calculateFeeDiscount(caller) | |
298 | - | let amountWithFee = fraction(amountWithoutFee, (feeScale6 - fraction(fee, feeDiscount, feeScale6, CEILING)), feeScale6) | |
299 | - | let governanceReward = fraction(amountWithoutFee, fraction(feeGovernance, feeDiscount, feeScale6, CEILING), feeScale6) | |
300 | - | if ((minAmountToReceive > amountWithFee)) | |
301 | - | then throw(((("Calculated amount to receive " + toString(amountWithFee)) + " is less than specified minimum ") + toString(minAmountToReceive))) | |
302 | - | else $Tuple3(amountWithoutFee, amountWithFee, governanceReward) | |
303 | - | } | |
120 | + | func collectState (result,source) = match source { | |
121 | + | case e: Issue|Burn|Reissue|ScriptTransfer|BinaryEntry|BooleanEntry|StringEntry|IntegerEntry => | |
122 | + | (result :+ e) | |
123 | + | case _ => | |
124 | + | result | |
125 | + | } | |
304 | 126 | ||
305 | 127 | ||
306 | - | func suspendSuspicious () = suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(accountBalanceWithStakedA)) + " ") + assetNameA) + ", ") + toString(accountBalanceWithStakedB)) + " ") + assetNameB) + ". State: ") + toString(balanceA)) + " ") + assetNameA) + ", ") + toString(balanceB)) + " ") + assetNameB)) | |
307 | - | ||
308 | - | ||
309 | - | func isActive () = if (active) | |
310 | - | then unit | |
311 | - | else throw("DApp is inactive at this moment") | |
128 | + | func collectData (result,source) = match source { | |
129 | + | case v: String => | |
130 | + | (result :+ v) | |
131 | + | case v: Int => | |
132 | + | (result :+ v) | |
133 | + | case v: Boolean => | |
134 | + | (result :+ v) | |
135 | + | case v: ByteVector => | |
136 | + | (result :+ v) | |
137 | + | case _ => | |
138 | + | throw() | |
139 | + | } | |
312 | 140 | ||
313 | 141 | ||
314 | 142 | @Callable(i) | |
315 | - | func init (firstHarvest) = { | |
316 | - | let $t088358912 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
317 | - | let pmtAmountA = $t088358912._1 | |
318 | - | let pmtAssetIdA = $t088358912._2 | |
319 | - | let $t089178994 = $Tuple2(i.payments[1].amount, i.payments[1].assetId) | |
320 | - | let pmtAmountB = $t089178994._1 | |
321 | - | let pmtAssetIdB = $t089178994._2 | |
322 | - | let $t089999076 = getAssetInfo(pmtAssetIdA) | |
323 | - | let pmtStrAssetIdA = $t089999076._1 | |
324 | - | let pmtAssetNameA = $t089999076._2 | |
325 | - | let pmtDecimalsA = $t089999076._3 | |
326 | - | let $t090819158 = getAssetInfo(pmtAssetIdB) | |
327 | - | let pmtStrAssetIdB = $t090819158._1 | |
328 | - | let pmtAssetNameB = $t090819158._2 | |
329 | - | let pmtDecimalsB = $t090819158._3 | |
330 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.callerPublicKey))) | |
331 | - | then throw("Only admin can call this function") | |
332 | - | else if (isDefined(getBoolean(this, kActive))) | |
333 | - | then throw("DApp is already active") | |
334 | - | else if ((pmtAssetIdA == pmtAssetIdB)) | |
335 | - | then throw("Assets must be different") | |
336 | - | else { | |
337 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
338 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
339 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
340 | - | let arg1 = pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN) | |
341 | - | let arg2 = pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN) | |
342 | - | let arg3 = pow(10, 0, shareDecimals, 0, 0, DOWN) | |
343 | - | let shareInitialSupply = fraction(arg1, arg2, arg3) | |
344 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
345 | - | let shareIssueId = calculateAssetId(shareIssue) | |
346 | - | let stake1 = if (containsElement(stakingAssets, pmtStrAssetIdA)) | |
347 | - | then invoke(this, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
348 | - | else 0 | |
349 | - | if ((stake1 == stake1)) | |
350 | - | then { | |
351 | - | let stake2 = if (containsElement(stakingAssets, pmtStrAssetIdB)) | |
352 | - | then invoke(this, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
353 | - | else 0 | |
354 | - | if ((stake2 == stake2)) | |
355 | - | then { | |
356 | - | let baseEntry = [StringEntry(kVersion, version), BooleanEntry(kActive, true), StringEntry(kAssetIdA, pmtStrAssetIdA), StringEntry(kAssetIdB, pmtStrAssetIdB), IntegerEntry(kBalanceA, pmtAmountA), IntegerEntry(kBalanceB, pmtAmountB), IntegerEntry(kFee, getIntegerValue(oracle, "base_fee_cpmm")), shareIssue, StringEntry(kShareAssetId, toBase58String(shareIssueId)), IntegerEntry(kShareAssetSupply, shareInitialSupply), ScriptTransfer(i.caller, shareInitialSupply, shareIssueId)] | |
357 | - | if (firstHarvest) | |
358 | - | then (baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]) | |
359 | - | else baseEntry | |
360 | - | } | |
361 | - | else throw("Strict value is not equal to itself.") | |
362 | - | } | |
363 | - | else throw("Strict value is not equal to itself.") | |
364 | - | } | |
365 | - | } | |
143 | + | func callFunction (funcName,args) = valueOrElse(isActive(), { | |
144 | + | let $t037383824 = { | |
145 | + | let $l = i.payments | |
146 | + | let $s = size($l) | |
147 | + | let $acc0 = $Tuple2(nil, nil) | |
148 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
149 | + | then $a | |
150 | + | else collectPayments($a, $l[$i]) | |
366 | 151 | ||
152 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
153 | + | then $a | |
154 | + | else throw("List size exceeds 10") | |
367 | 155 | ||
156 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
157 | + | } | |
158 | + | let paymentAmounts = $t037383824._1 | |
159 | + | let paymentAssetIds = $t037383824._2 | |
160 | + | let $t038273983 = { | |
161 | + | let @ = reentrantInvoke(cpmmContract, funcName, [i.caller.bytes, args, paymentAmounts, paymentAssetIds], nil) | |
162 | + | if ($isInstanceOf(@, "(List[Any], List[Any])")) | |
163 | + | then @ | |
164 | + | else throw(($getType(@) + " couldn't be cast to (List[Any], List[Any])")) | |
165 | + | } | |
166 | + | if (($t038273983 == $t038273983)) | |
167 | + | then { | |
168 | + | let data = $t038273983._2 | |
169 | + | let actions = $t038273983._1 | |
170 | + | let mappedData = { | |
171 | + | let $l = data | |
172 | + | let $s = size($l) | |
173 | + | let $acc0 = nil | |
174 | + | func $f1_1 ($a,$i) = if (($i >= $s)) | |
175 | + | then $a | |
176 | + | else collectData($a, $l[$i]) | |
368 | 177 | ||
369 | - | @Callable(i) | |
370 | - | func initWithInitRatio (amtAssetA,amtAssetB,strAssetIdA,strAssetIdB,firstHarvest) = { | |
371 | - | let $t01166311750 = getAssetInfoFromString(strAssetIdA) | |
372 | - | let pmtStrAssetIdA = $t01166311750._1 | |
373 | - | let pmtAssetNameA = $t01166311750._2 | |
374 | - | let pmtDecimalsA = $t01166311750._3 | |
375 | - | let $t01175511842 = getAssetInfoFromString(strAssetIdB) | |
376 | - | let pmtStrAssetIdB = $t01175511842._1 | |
377 | - | let pmtAssetNameB = $t01175511842._2 | |
378 | - | let pmtDecimalsB = $t01175511842._3 | |
379 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.callerPublicKey))) | |
380 | - | then throw("Only admin can call this function") | |
381 | - | else if (isDefined(getBoolean(this, kActive))) | |
382 | - | then throw("DApp is already active") | |
383 | - | else if ((strAssetIdA == strAssetIdB)) | |
384 | - | then throw("Assets must be different") | |
385 | - | else { | |
386 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
387 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
388 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
389 | - | let shareInitialSupply = 0 | |
390 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
391 | - | let shareIssueId = calculateAssetId(shareIssue) | |
392 | - | let baseEntry = [StringEntry(kVersion, version), BooleanEntry(kActive, true), StringEntry(kAssetIdA, pmtStrAssetIdA), StringEntry(kAssetIdB, pmtStrAssetIdB), IntegerEntry(kBalanceInitA, amtAssetA), IntegerEntry(kBalanceInitB, amtAssetB), IntegerEntry(kBalanceA, 0), IntegerEntry(kBalanceB, 0), IntegerEntry(kFee, getIntegerValue(oracle, "base_fee_cpmm")), shareIssue, StringEntry(kShareAssetId, toBase58String(shareIssueId)), IntegerEntry(kShareAssetSupply, shareInitialSupply)] | |
393 | - | if (firstHarvest) | |
394 | - | then (baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]) | |
395 | - | else baseEntry | |
396 | - | } | |
397 | - | } | |
178 | + | func $f1_2 ($a,$i) = if (($i >= $s)) | |
179 | + | then $a | |
180 | + | else throw("List size exceeds 10") | |
398 | 181 | ||
182 | + | $f1_2($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($f1_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
183 | + | } | |
184 | + | let mappedActions = { | |
185 | + | let $l = actions | |
186 | + | let $s = size($l) | |
187 | + | let $acc0 = nil | |
188 | + | func $f2_1 ($a,$i) = if (($i >= $s)) | |
189 | + | then $a | |
190 | + | else collectState($a, $l[$i]) | |
399 | 191 | ||
192 | + | func $f2_2 ($a,$i) = if (($i >= $s)) | |
193 | + | then $a | |
194 | + | else throw("List size exceeds 15") | |
400 | 195 | ||
401 | - | @Callable(i) | |
402 | - | func keepLimitForFirstHarvest (shareLimit) = valueOrElse(isActive(), if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.callerPublicKey))) | |
403 | - | then throw("Only admin can call this function") | |
404 | - | else [IntegerEntry(kShareLimit, shareLimit)]) | |
405 | - | ||
406 | - | ||
407 | - | ||
408 | - | @Callable(i) | |
409 | - | func replenishWithTwoTokens (slippageTolerance) = valueOrElse(isActive(), { | |
410 | - | let pmtAssetIdA = i.payments[0].assetId | |
411 | - | let pmtAssetIdB = i.payments[1].assetId | |
412 | - | let pmtAmountA = i.payments[0].amount | |
413 | - | let pmtAmountB = i.payments[1].amount | |
414 | - | let $t01422114298 = getAssetInfo(pmtAssetIdA) | |
415 | - | let pmtStrAssetIdA = $t01422114298._1 | |
416 | - | let pmtAssetNameA = $t01422114298._2 | |
417 | - | let pmtDecimalsA = $t01422114298._3 | |
418 | - | let $t01430314380 = getAssetInfo(pmtAssetIdB) | |
419 | - | let pmtStrAssetIdB = $t01430314380._1 | |
420 | - | let pmtAssetNameB = $t01430314380._2 | |
421 | - | let pmtDecimalsB = $t01430314380._3 | |
422 | - | let inital = if (if ((balanceA == 0)) | |
423 | - | then (balanceB == 0) | |
424 | - | else false) | |
425 | - | then true | |
426 | - | else false | |
427 | - | let tokenRatio = if (inital) | |
428 | - | then fraction(fraction(assetInitA, scaleValue8, pmtAmountA), scaleValue3, fraction(assetInitB, scaleValue8, pmtAmountB)) | |
429 | - | else fraction(fraction(balanceA, scaleValue8, pmtAmountA), scaleValue3, fraction(balanceB, scaleValue8, pmtAmountB)) | |
430 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
431 | - | let shareTokenToPayAmount = if (inital) | |
432 | - | then fraction(pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN), pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN), pow(10, 0, shareDecimals, 0, 0, DOWN)) | |
433 | - | else fraction(min([fraction(pmtAmountA, scaleValue8, balanceA), fraction(pmtAmountB, scaleValue8, balanceB)]), shareAssetSupply, scaleValue8) | |
434 | - | if (if ((0 > slippageTolerance)) | |
435 | - | then true | |
436 | - | else (slippageTolerance > slippageToleranceDelimiter)) | |
437 | - | then throw(((("Slippage tolerance must be between 0 and " + toString(slippageToleranceDelimiter)) + " inclusively. Actual: ") + toString(slippageTolerance))) | |
438 | - | else if ((size(i.payments) != 2)) | |
439 | - | then throw("Two attached assets expected") | |
440 | - | else if (if ((pmtAssetIdA != assetIdA)) | |
441 | - | then true | |
442 | - | else (pmtAssetIdB != assetIdB)) | |
443 | - | then throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
444 | - | else if (if ((((scaleValue3 * (slippageToleranceDelimiter - slippageTolerance)) / slippageToleranceDelimiter) > tokenRatio)) | |
445 | - | then true | |
446 | - | else (tokenRatio > ((scaleValue3 * (slippageToleranceDelimiter + slippageTolerance)) / slippageToleranceDelimiter))) | |
447 | - | then throw("Incorrect assets amount: amounts must have the contract ratio") | |
448 | - | else if ((shareTokenToPayAmount == 0)) | |
449 | - | then throw("Too small amount to replenish") | |
450 | - | else if (!(hasEnoughBalance)) | |
451 | - | then ([ScriptTransfer(i.caller, pmtAmountA, pmtAssetIdA), ScriptTransfer(i.caller, pmtAmountB, pmtAssetIdB)] ++ suspendSuspicious()) | |
452 | - | else { | |
453 | - | let stake1 = if (containsElement(stakingAssets, pmtStrAssetIdA)) | |
454 | - | then invoke(this, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
455 | - | else 0 | |
456 | - | if ((stake1 == stake1)) | |
457 | - | then { | |
458 | - | let stake2 = if (containsElement(stakingAssets, pmtStrAssetIdB)) | |
459 | - | then invoke(this, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
460 | - | else 0 | |
461 | - | if ((stake2 == stake2)) | |
462 | - | then [Reissue(shareAssetId, shareTokenToPayAmount, true), IntegerEntry(kBalanceA, (balanceA + pmtAmountA)), IntegerEntry(kBalanceB, (balanceB + pmtAmountB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), ScriptTransfer(i.caller, shareTokenToPayAmount, shareAssetId)] | |
463 | - | else throw("Strict value is not equal to itself.") | |
464 | - | } | |
465 | - | else throw("Strict value is not equal to itself.") | |
466 | - | } | |
196 | + | $f2_2($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($f2_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15) | |
197 | + | } | |
198 | + | $Tuple2(mappedActions, mappedData) | |
199 | + | } | |
200 | + | else throw("Strict value is not equal to itself.") | |
467 | 201 | }) | |
468 | 202 | ||
469 | 203 | ||
470 | 204 | ||
471 | 205 | @Callable(i) | |
472 | - | func withdraw () = valueOrElse(isActive(), { | |
473 | - | let $t01718017255 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
474 | - | let pmtAmount = $t01718017255._1 | |
475 | - | let pmtAssetId = $t01718017255._2 | |
476 | - | let amountToPayA = fraction(pmtAmount, balanceA, shareAssetSupply) | |
477 | - | let amountToPayB = fraction(pmtAmount, balanceB, shareAssetSupply) | |
478 | - | if ((size(i.payments) != 1)) | |
479 | - | then throw("One attached payment expected") | |
480 | - | else if ((pmtAssetId != shareAssetId)) | |
481 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
482 | - | else if (!(hasEnoughBalance)) | |
483 | - | then ([ScriptTransfer(i.caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious()) | |
484 | - | else { | |
485 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
486 | - | then invoke(this, "stakeUnstake", [false, amountToPayA, strAssetIdA], nil) | |
487 | - | else 0 | |
488 | - | if ((stake1 == stake1)) | |
489 | - | then { | |
490 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
491 | - | then invoke(this, "stakeUnstake", [false, amountToPayB, strAssetIdB], nil) | |
492 | - | else 0 | |
493 | - | if ((stake2 == stake2)) | |
494 | - | then [IntegerEntry(kBalanceA, (balanceA - amountToPayA)), IntegerEntry(kBalanceB, (balanceB - amountToPayB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply - pmtAmount)), Burn(shareAssetId, pmtAmount), ScriptTransfer(i.caller, amountToPayA, assetIdA), ScriptTransfer(i.caller, amountToPayB, assetIdB)] | |
495 | - | else throw("Strict value is not equal to itself.") | |
496 | - | } | |
497 | - | else throw("Strict value is not equal to itself.") | |
498 | - | } | |
499 | - | }) | |
206 | + | func shutdown () = valueOrElse(isAdminCall(i.callerPublicKey), if (!(active)) | |
207 | + | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, kCause), "the cause wasn't specified"))) | |
208 | + | else suspend("Paused by admin")) | |
500 | 209 | ||
501 | 210 | ||
502 | 211 | ||
503 | 212 | @Callable(i) | |
504 | - | func exchange (minAmountToReceive) = valueOrElse(isActive(), { | |
505 | - | let $t01855418629 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
506 | - | let pmtAmount = $t01855418629._1 | |
507 | - | let pmtAssetId = $t01855418629._2 | |
508 | - | if (if ((balanceA == 0)) | |
509 | - | then true | |
510 | - | else (balanceB == 0)) | |
511 | - | then throw("Can't exchange with zero balance") | |
512 | - | else if ((0 >= minAmountToReceive)) | |
513 | - | then throw(("Minimal amount to receive must be positive. Actual: " + toString(minAmountToReceive))) | |
514 | - | else if ((size(i.payments) != 1)) | |
515 | - | then throw("One attached payment expected") | |
516 | - | else if (!(hasEnoughBalance)) | |
517 | - | then ([ScriptTransfer(i.caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious()) | |
518 | - | else if ((pmtAssetId == assetIdA)) | |
519 | - | then { | |
520 | - | let assetIdSend = assetIdB | |
521 | - | let $t01918019318 = calculateFees(pmtAmount, minAmountToReceive, balanceA, balanceB, i.originCaller) | |
522 | - | let amountWithoutFee = $t01918019318._1 | |
523 | - | let amountWithFee = $t01918019318._2 | |
524 | - | let governanceReward = $t01918019318._3 | |
525 | - | let newBalanceA = (balanceA + pmtAmount) | |
526 | - | let newBalanceB = ((balanceB - amountWithFee) - governanceReward) | |
527 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
528 | - | then invoke(this, "stakeUnstake", [true, pmtAmount, strAssetIdA], nil) | |
529 | - | else 0 | |
530 | - | if ((stake1 == stake1)) | |
531 | - | then { | |
532 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
533 | - | then invoke(this, "stakeUnstake", [false, (amountWithFee + governanceReward), strAssetIdB], nil) | |
534 | - | else 0 | |
535 | - | if ((stake2 == stake2)) | |
536 | - | then $Tuple2([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(moneyBoxAddress, governanceReward, assetIdSend)], $Tuple2(amountWithFee, assetIdSend)) | |
537 | - | else throw("Strict value is not equal to itself.") | |
538 | - | } | |
539 | - | else throw("Strict value is not equal to itself.") | |
540 | - | } | |
541 | - | else if ((pmtAssetId == assetIdB)) | |
542 | - | then { | |
543 | - | let assetIdSend = assetIdA | |
544 | - | let $t02031020448 = calculateFees(pmtAmount, minAmountToReceive, balanceB, balanceA, i.originCaller) | |
545 | - | let amountWithoutFee = $t02031020448._1 | |
546 | - | let amountWithFee = $t02031020448._2 | |
547 | - | let governanceReward = $t02031020448._3 | |
548 | - | let newBalanceA = ((balanceA - amountWithFee) - governanceReward) | |
549 | - | let newBalanceB = (balanceB + pmtAmount) | |
550 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
551 | - | then invoke(this, "stakeUnstake", [false, (amountWithFee + governanceReward), strAssetIdA], nil) | |
552 | - | else 0 | |
553 | - | if ((stake1 == stake1)) | |
554 | - | then { | |
555 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
556 | - | then invoke(this, "stakeUnstake", [true, pmtAmount, strAssetIdB], nil) | |
557 | - | else 0 | |
558 | - | if ((stake2 == stake2)) | |
559 | - | then $Tuple2([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), ScriptTransfer(i.caller, amountWithFee, assetIdSend), ScriptTransfer(moneyBoxAddress, governanceReward, assetIdSend)], $Tuple2(amountWithFee, assetIdSend)) | |
560 | - | else throw("Strict value is not equal to itself.") | |
561 | - | } | |
562 | - | else throw("Strict value is not equal to itself.") | |
563 | - | } | |
564 | - | else throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
565 | - | }) | |
213 | + | func activate () = valueOrElse(isAdminCall(i.callerPublicKey), if (active) | |
214 | + | then throw("DApp is already active") | |
215 | + | else [BooleanEntry(kActive, true), DeleteEntry(kCause)]) | |
566 | 216 | ||
567 | 217 | ||
568 | 218 | ||
569 | 219 | @Callable(i) | |
570 | - | func shutdown () = if (!(active)) | |
571 | - | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, kCause), "the cause wasn't specified"))) | |
572 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
573 | - | then throw("Only admin can call this function") | |
574 | - | else suspend("Paused by admin") | |
575 | - | ||
576 | - | ||
577 | - | ||
578 | - | @Callable(i) | |
579 | - | func activate () = if (active) | |
580 | - | then throw("DApp is already active") | |
581 | - | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
582 | - | then throw("Only admin can call this function") | |
583 | - | else [BooleanEntry(kActive, true), DeleteEntry(kCause)] | |
584 | - | ||
585 | - | ||
586 | - | ||
587 | - | @Callable(i) | |
588 | - | func takeIntoAccountExtraFunds () = valueOrElse(isActive(), { | |
589 | - | let amountEnrollA = (accountBalanceWithStakedA - balanceA) | |
590 | - | let amountEnrollB = (accountBalanceWithStakedB - balanceB) | |
591 | - | if ((i.caller != moneyBoxAddress)) | |
592 | - | then throw("Only the wallet can call this function") | |
593 | - | else if (if ((0 > amountEnrollA)) | |
594 | - | then true | |
595 | - | else (0 > amountEnrollB)) | |
596 | - | then suspend("Enroll amount negative") | |
597 | - | else if (if ((amountEnrollA == 0)) | |
598 | - | then (amountEnrollB == 0) | |
599 | - | else false) | |
600 | - | then throw("No money to take") | |
601 | - | else { | |
602 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
603 | - | then invoke(this, "stakeUnstake", [true, amountEnrollA, strAssetIdA], nil) | |
604 | - | else 0 | |
605 | - | if ((stake1 == stake1)) | |
606 | - | then { | |
607 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
608 | - | then invoke(this, "stakeUnstake", [true, amountEnrollB, strAssetIdB], nil) | |
609 | - | else 0 | |
610 | - | if ((stake2 == stake2)) | |
611 | - | then [IntegerEntry(kBalanceA, (balanceA + amountEnrollA)), IntegerEntry(kBalanceB, (balanceB + amountEnrollB)), IntegerEntry(("last_income_" + strAssetIdA), amountEnrollA), IntegerEntry(("last_income_" + strAssetIdB), amountEnrollB)] | |
612 | - | else throw("Strict value is not equal to itself.") | |
613 | - | } | |
614 | - | else throw("Strict value is not equal to itself.") | |
615 | - | } | |
616 | - | }) | |
617 | - | ||
618 | - | ||
619 | - | ||
620 | - | @Callable(i) | |
621 | - | func stakeUnstake (stake,amount,assetIdString) = if ((i.caller != this)) | |
622 | - | then throw("Only contract itself can invoke this function") | |
220 | + | func stakeUnstake (stake,amount,assetIdString) = valueOrElse(isGlobalCaller(i.caller), valueOrElse(isActive(), if ((i.caller != cpmmContract)) | |
221 | + | then throw("Only global Contract can invoke this function") | |
623 | 222 | else if ((assetIdString == "WAVES")) | |
624 | 223 | then { | |
625 | 224 | let pool = addressFromStringValue(valueOrErrorMessage(getString(oracle, kLeasingPool), "No leasing pool in oracle")) | |
626 | 225 | let leasingId = getBinary(this, kLeasingId) | |
627 | 226 | let leasingAmount = valueOrElse(getInteger(this, kLeasingAmount), 0) | |
628 | 227 | let newLeaseAmount = if (stake) | |
629 | 228 | then (leasingAmount + amount) | |
630 | 229 | else (leasingAmount - amount) | |
631 | 230 | let newLease = Lease(pool, newLeaseAmount) | |
632 | 231 | let newLeaseId = calculateLeaseId(newLease) | |
633 | 232 | let baseEtry = [newLease, BinaryEntry(kLeasingId, newLeaseId), IntegerEntry(kLeasingAmount, newLeaseAmount)] | |
634 | 233 | match leasingId { | |
635 | 234 | case lId: ByteVector => | |
636 | 235 | ([LeaseCancel(lId)] ++ baseEtry) | |
637 | 236 | case _ => | |
638 | 237 | baseEtry | |
639 | 238 | } | |
640 | 239 | } | |
641 | 240 | else { | |
642 | - | let $ | |
643 | - | let call = $ | |
644 | - | let addr = $ | |
645 | - | let params = $ | |
646 | - | let payments = $ | |
241 | + | let $t059776080 = calcStakingParams(stake, amount, fromBase58String(assetIdString)) | |
242 | + | let call = $t059776080._1 | |
243 | + | let addr = $t059776080._2 | |
244 | + | let params = $t059776080._3 | |
245 | + | let payments = $t059776080._4 | |
647 | 246 | let inv = invoke(addr, call, params, payments) | |
648 | 247 | if ((inv == inv)) | |
649 | 248 | then nil | |
650 | 249 | else throw("Strict value is not equal to itself.") | |
651 | - | } | |
250 | + | })) | |
652 | 251 | ||
653 | 252 | ||
654 | 253 | ||
655 | 254 | @Callable(i) | |
656 | - | func stakeAll () = valueOrElse(isActive(), if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3], i.callerPublicKey))) | |
657 | - | then throw("Only admin can call this function") | |
658 | - | else { | |
659 | - | let stake1 = if (containsElement(stakingAssets, strAssetIdA)) | |
660 | - | then { | |
661 | - | let amountA = (balanceA - stakedAmountA) | |
662 | - | if ((amountA > 0)) | |
663 | - | then invoke(this, "stakeUnstake", [true, amountA, strAssetIdA], nil) | |
664 | - | else 0 | |
665 | - | } | |
666 | - | else 0 | |
667 | - | if ((stake1 == stake1)) | |
668 | - | then { | |
669 | - | let stake2 = if (containsElement(stakingAssets, strAssetIdB)) | |
670 | - | then { | |
671 | - | let amountB = (balanceB - stakedAmountB) | |
672 | - | if ((amountB > 0)) | |
673 | - | then invoke(this, "stakeUnstake", [true, amountB, strAssetIdB], nil) | |
674 | - | else 0 | |
675 | - | } | |
676 | - | else 0 | |
677 | - | if ((stake2 == stake2)) | |
678 | - | then nil | |
679 | - | else throw("Strict value is not equal to itself.") | |
680 | - | } | |
681 | - | else throw("Strict value is not equal to itself.") | |
682 | - | }) | |
255 | + | func reissueShareToken (amount) = valueOrElse(isGlobalCaller(i.caller), valueOrElse(isActive(), { | |
256 | + | let shareAssetId = fromBase58String(getStringValue(this, kShareAssetId)) | |
257 | + | [Reissue(shareAssetId, amount, true), ScriptTransfer(i.caller, amount, shareAssetId)] | |
258 | + | })) | |
683 | 259 | ||
684 | 260 | ||
685 | 261 | @Verifier(tx) | |
686 | 262 | func verify () = { | |
687 | 263 | let multiSignedByAdmins = { | |
688 | 264 | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
689 | 265 | then 1 | |
690 | 266 | else 0 | |
691 | 267 | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
692 | 268 | then 1 | |
693 | 269 | else 0 | |
694 | 270 | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
695 | 271 | then 1 | |
696 | 272 | else 0 | |
697 | 273 | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
698 | 274 | } | |
699 | - | match tx { | |
700 | - | case inv: InvokeScriptTransaction => | |
701 | - | let callTakeIntoAccount = if ((inv.dApp == this)) | |
702 | - | then (inv.function == "takeIntoAccountExtraFunds") | |
703 | - | else false | |
704 | - | let signedByAdmin = if (if (if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
705 | - | then true | |
706 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey2)) | |
707 | - | then true | |
708 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey3)) | |
709 | - | then true | |
710 | - | else sigVerify(tx.bodyBytes, tx.proofs[0], adminInvokePubKey) | |
711 | - | if (if (callTakeIntoAccount) | |
712 | - | then signedByAdmin | |
713 | - | else false) | |
714 | - | then true | |
715 | - | else multiSignedByAdmins | |
716 | - | case _ => | |
717 | - | multiSignedByAdmins | |
718 | - | } | |
275 | + | multiSignedByAdmins | |
719 | 276 | } | |
720 | 277 |
github/deemru/w8io/169f3d6 80.23 ms ◑