tx · DPyp1jZciazAD3rf9Q7azcsWbqaaB7Unonk6KPBh4d2T 3MzqQ3HKdkHmJmk9mDhAeAMxmK5D2ztdAe5: -0.05000000 Waves 2022.11.25 23:32 [2333104] smart account 3MzqQ3HKdkHmJmk9mDhAeAMxmK5D2ztdAe5 > SELF 0.00000000 Waves
{ "type": 13, "id": "DPyp1jZciazAD3rf9Q7azcsWbqaaB7Unonk6KPBh4d2T", "fee": 5000000, "feeAssetId": null, "timestamp": 1669408349723, "version": 2, "chainId": 84, "sender": "3MzqQ3HKdkHmJmk9mDhAeAMxmK5D2ztdAe5", "senderPublicKey": "FEnkfXnQZkk1FmjhH6QZqyK2taN6ngnZBexevKxouLUM", "proofs": [ "5pm8AB2HrfJBtW5BSy33FtviGH9eu4AW8aBD4KPHsXqUBX2WA6siAbKscCQexVDiMNgFyRrZ8N2fn4GbarTjScvR", "5mLG5pvFYieH7ZYXW8qdPsb2LMNDnxsDPqReg3rU8ayytnT883FUQ4H4qAM6mYrmy52vDcGwZQRrMqr6vy88U6Hi" ], "script": "base64:BgIkCAISBAoCCBgSABIAEgUKAwQBCBIDCgEBEgMKAQESABIDCgEBKQAHa0FjdGl2ZQIGYWN0aXZlAAtrQWN0aXZlR2xvYgIUYWN0aXZlX2FsbF9jb250cmFjdHMABmtDYXVzZQIOc2h1dGRvd25fY2F1c2UADGtVU0ROQWRkcmVzcwIYc3Rha2luZ191c2RubnNidF9hZGRyZXNzAAxrRVVSTkFkZHJlc3MCFHN0YWtpbmdfZXVybl9hZGRyZXNzAAxrTGVhc2luZ1Bvb2wCD2xlYXNpbmdfYWRkcmVzcwAOa0xlYXNpbmdBbW91bnQCDmxlYXNpbmdfYW1vdW50AAprTGVhc2luZ0lkAgpsZWFzaW5nX2lkAA1rQWRtaW5QdWJLZXkxAgthZG1pbl9wdWJfMQANa0FkbWluUHViS2V5MgILYWRtaW5fcHViXzIADWtBZG1pblB1YktleTMCC2FkbWluX3B1Yl8zABJrQWRtaW5JbnZva2VQdWJ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NhbGxlcgUGYW1vdW50BQxzaGFyZUFzc2V0SWQFA25pbAFpARZyZXBsZW5pc2hXaXRoVHdvVG9rZW5zARFzbGlwcGFnZVRvbGVyYW5jZQkBCmNhbGxDb21tb24EAhZyZXBsZW5pc2hXaXRoVHdvVG9rZW5zCAgFAWkGY2FsbGVyBWJ5dGVzCQDMCAICBWZhbHNlCQDMCAICATAFA25pbAgFAWkIcGF5bWVudHMBaQEId2l0aGRyYXcACQEKY2FsbENvbW1vbgQCCHdpdGhkcmF3CAgFAWkGY2FsbGVyBWJ5dGVzCQDMCAICATAFA25pbAgFAWkIcGF5bWVudHMBaQEIZXhjaGFuZ2UBEm1pbkFtb3VudFRvUmVjZWl2ZQkBCmNhbGxDb21tb24EAghleGNoYW5nZQgIBQFpBmNhbGxlcgVieXRlcwkAzAgCCQCkAwEFEm1pbkFtb3VudFRvUmVjZWl2ZQUDbmlsCAUBaQhwYXltZW50cwECdHgBBnZlcmlmeQAEE211bHRpU2lnbmVkQnlBZG1pbnMEEmFkbWluUHViS2V5MVNpZ25lZAMJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAFDGFkbWluUHViS2V5MQABAAAEEmFkbWluUHViS2V5MlNpZ25lZAMJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAEFDGFkbWluUHViS2V5MgABAAAEEmFkbWluUHViS2V5M1NpZ25lZAMJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAIFDGFkbWluUHViS2V5MwABAAAJAGcCCQBkAgkAZAIFEmFkbWluUHViS2V5MVNpZ25lZAUSYWRtaW5QdWJLZXkyU2lnbmVkBRJhZG1pblB1YktleTNTaWduZWQAAgUTbXVsdGlTaWduZWRCeUFkbWluc1AR26c=", "height": 2333104, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6gHBgENsotbG5F4UtyAVR6rPs49dpK4euuHh7AUaovPz Next: GBhQcfEcGr6EdoJqrBTJxNS8KRPWvG1SDmq5HHz6o8aY Diff:
Old | New | Differences | |
---|---|---|---|
1 | 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" | |
6 | + | let kActiveGlob = "active_all_contracts" | |
27 | 7 | ||
28 | 8 | 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 | 9 | ||
42 | 10 | let kUSDNAddress = "staking_usdnnsbt_address" | |
43 | 11 | ||
44 | 12 | let kEURNAddress = "staking_eurn_address" | |
45 | 13 | ||
14 | + | let kLeasingPool = "leasing_address" | |
15 | + | ||
46 | 16 | let kLeasingAmount = "leasing_amount" | |
47 | 17 | ||
48 | - | let kUSDNAssetId = "usdn_asset_id" | |
49 | - | ||
50 | - | let kEURNAssetId = "eurn_asset_id" | |
51 | - | ||
52 | - | let kStakingAssets = "staking_assets" | |
53 | - | ||
54 | - | let kOracleActive = "active_all_contracts" | |
55 | - | ||
56 | - | let kOracleActiveExchangers = "active_global_exchangers" | |
57 | - | ||
58 | - | let kDiscounts = "discounts" | |
59 | - | ||
60 | - | let kDiscountValues = "discount_values" | |
61 | - | ||
62 | - | let kUserGSwopInGov = "_GSwop_amount" | |
63 | - | ||
64 | - | let kUserSwopInGov = "_SWOP_amount" | |
65 | - | ||
66 | - | let kOraclePool = "pool_" | |
18 | + | let kLeasingId = "leasing_id" | |
67 | 19 | ||
68 | 20 | let kAdminPubKey1 = "admin_pub_1" | |
69 | 21 | ||
73 | 25 | ||
74 | 26 | let kAdminInvokePubKey = "admin_invoke_pub" | |
75 | 27 | ||
76 | - | let | |
28 | + | let kCpmmContract = "cpmm_contract" | |
77 | 29 | ||
78 | - | let | |
30 | + | let kUSDNAssetId = "usdn_asset_id" | |
79 | 31 | ||
80 | - | let | |
32 | + | let kEURNAssetId = "eurn_asset_id" | |
81 | 33 | ||
82 | - | let kFarmingAddress = "farming_address" | |
34 | + | let kStakingAssets = "staking_assets" | |
35 | + | ||
36 | + | let kShareAssetId = "share_asset_id" | |
83 | 37 | ||
84 | 38 | let oracle = Address(base58'3MvVBtsXroQpy1tsPw21TU2ET9A8WfmrNjz') | |
85 | 39 | ||
97 | 51 | ||
98 | 52 | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
99 | 53 | ||
100 | - | let | |
54 | + | let adminPubKeyInvoke = getBase58FromOracle(kAdminInvokePubKey) | |
101 | 55 | ||
102 | - | let | |
56 | + | let stakingUSDNAddress = Address(getBase58FromOracle(kUSDNAddress)) | |
103 | 57 | ||
104 | - | let | |
58 | + | let stakingEURNAddress = Address(getBase58FromOracle(kEURNAddress)) | |
105 | 59 | ||
106 | - | let govAddress = Address(getBase58FromOracle(kGovAddress)) | |
107 | - | ||
108 | - | let farmingAddress = Address(getBase58FromOracle(kFarmingAddress)) | |
60 | + | let cpmmContract = Address(getBase58FromOracle(kCpmmContract)) | |
109 | 61 | ||
110 | 62 | let USDN = getBase58FromOracle(kUSDNAssetId) | |
111 | 63 | ||
113 | 65 | ||
114 | 66 | let stakingAssets = getStringValue(oracle, kStakingAssets) | |
115 | 67 | ||
116 | - | let | |
68 | + | let activeGlob = valueOrElse(getBoolean(oracle, kActiveGlob), true) | |
117 | 69 | ||
118 | - | let | |
70 | + | let active = valueOrElse(getBoolean(this, kActive), true) | |
119 | 71 | ||
120 | - | let basePeriod = valueOrErrorMessage(getInteger(votingAddress, kBasePeriod), "Empty kBasePeriod") | |
121 | - | ||
122 | - | let startHeight = valueOrErrorMessage(getInteger(votingAddress, kStartHeight), "Empty kStartHeight") | |
123 | - | ||
124 | - | let periodLength = valueOrErrorMessage(getInteger(votingAddress, kPeriodLength), "Empty kPeriodLength") | |
125 | - | ||
126 | - | let firstHarvestEndPeriod = ((basePeriod + ((height - startHeight) / periodLength)) + 3) | |
127 | - | ||
128 | - | let active = if (getBooleanValue(oracle, kOracleActive)) | |
129 | - | then getBooleanValue(oracle, kOracleActiveExchangers) | |
130 | - | else false | |
131 | - | ||
132 | - | let feeScale6 = 1000000 | |
133 | - | ||
134 | - | let scale8 = 100000000 | |
135 | - | ||
136 | - | func accountBalance (assetId,pool) = match assetId { | |
137 | - | case id: ByteVector => | |
138 | - | assetBalance(pool, id) | |
139 | - | case waves: Unit => | |
140 | - | wavesBalance(pool).available | |
141 | - | case _ => | |
142 | - | throw("Match error") | |
143 | - | } | |
72 | + | func isActive () = if (if (active) | |
73 | + | then activeGlob | |
74 | + | else false) | |
75 | + | then unit | |
76 | + | else throw("DApp is inactive at this moment") | |
144 | 77 | ||
145 | 78 | ||
146 | - | func stakedAmount (assetId,pool) = { | |
147 | - | let stakedAmountCalculated = match assetId { | |
148 | - | case aId: ByteVector => | |
149 | - | if ((aId == USDN)) | |
150 | - | then getInteger(stakingUSDNAddress, ((("rpd_balance_" + toBase58String(aId)) + "_") + toString(pool))) | |
151 | - | else if ((aId == EURN)) | |
152 | - | then getInteger(stakingEURNAddress, ((("%s%s%s__stakingBalance__" + toBase58String(aId)) + "__") + toString(pool))) | |
153 | - | else 0 | |
154 | - | case _: Unit => | |
155 | - | valueOrElse(getInteger(pool, kLeasingAmount), 0) | |
156 | - | case _ => | |
157 | - | throw("Match error") | |
158 | - | } | |
159 | - | match stakedAmountCalculated { | |
160 | - | case i: Int => | |
161 | - | i | |
162 | - | case _ => | |
163 | - | 0 | |
164 | - | } | |
165 | - | } | |
79 | + | func isGlobalCaller (caller) = if ((caller == cpmmContract)) | |
80 | + | then unit | |
81 | + | else throw("Only global Contract can invoke this function") | |
166 | 82 | ||
167 | 83 | ||
168 | - | func getAssetInfo (assetId) = match assetId { | |
169 | - | case id: String|ByteVector => | |
170 | - | let $t040054177 = match id { | |
171 | - | case aId: ByteVector => | |
172 | - | $Tuple2(toBase58String(aId), aId) | |
173 | - | case aId: String => | |
174 | - | $Tuple2(aId, fromBase58String(aId)) | |
175 | - | case _ => | |
176 | - | throw("Match error") | |
177 | - | } | |
178 | - | let stringId = $t040054177._1 | |
179 | - | let bytesId = $t040054177._2 | |
180 | - | let info = valueOrErrorMessage(assetInfo(bytesId), (("Asset " + stringId) + " doesn't exist")) | |
181 | - | $Tuple3(stringId, info.name, info.decimals) | |
182 | - | case waves: Unit => | |
183 | - | $Tuple3("WAVES", "WAVES", 8) | |
184 | - | case _ => | |
185 | - | throw("Match error") | |
186 | - | } | |
84 | + | func isAdminCall (callerPubKey) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], callerPubKey)) | |
85 | + | then unit | |
86 | + | else throw("Only admin can call this function") | |
187 | 87 | ||
188 | 88 | ||
189 | 89 | func suspend (cause) = [BooleanEntry(kActive, false), StringEntry(kCause, cause)] | |
190 | 90 | ||
191 | 91 | ||
192 | - | func calculateFeeDiscount (userAddr) = { | |
193 | - | let swopAmount = valueOrElse(getInteger(govAddress, (toString(userAddr) + kUserSwopInGov)), 0) | |
194 | - | let gSwopAmount = valueOrElse(getInteger(govAddress, (toString(userAddr) + kUserGSwopInGov)), swopAmount) | |
195 | - | let discountValues = split(getStringValue(oracle, kDiscountValues), ",") | |
196 | - | let discounts = split(getStringValue(oracle, kDiscounts), ",") | |
197 | - | if (if ((gSwopAmount >= parseIntValue(discountValues[0]))) | |
198 | - | then (parseIntValue(discountValues[1]) > gSwopAmount) | |
199 | - | else false) | |
200 | - | then (feeScale6 - parseIntValue(discounts[0])) | |
201 | - | else if (if ((gSwopAmount >= parseIntValue(discountValues[1]))) | |
202 | - | then (parseIntValue(discountValues[2]) > gSwopAmount) | |
203 | - | else false) | |
204 | - | then (feeScale6 - parseIntValue(discounts[1])) | |
205 | - | else if (if ((gSwopAmount >= parseIntValue(discountValues[2]))) | |
206 | - | then (parseIntValue(discountValues[3]) > gSwopAmount) | |
207 | - | else false) | |
208 | - | then (feeScale6 - parseIntValue(discounts[2])) | |
209 | - | else if (if ((gSwopAmount >= parseIntValue(discountValues[3]))) | |
210 | - | then (parseIntValue(discountValues[4]) > gSwopAmount) | |
211 | - | else false) | |
212 | - | then (feeScale6 - parseIntValue(discounts[3])) | |
213 | - | else if ((gSwopAmount >= parseIntValue(discountValues[4]))) | |
214 | - | then (feeScale6 - parseIntValue(discounts[4])) | |
215 | - | else feeScale6 | |
92 | + | func calcStakingFuncAndAddres (stake,assetId) = if (stake) | |
93 | + | then if ((assetId == USDN)) | |
94 | + | then $Tuple2("lockNeutrino", stakingUSDNAddress) | |
95 | + | else $Tuple2("startStaking", stakingEURNAddress) | |
96 | + | else if ((assetId == USDN)) | |
97 | + | then $Tuple2("unlockNeutrino", stakingUSDNAddress) | |
98 | + | else $Tuple2("stopStaking", stakingEURNAddress) | |
99 | + | ||
100 | + | ||
101 | + | func calcStakingParams (stake,amount,assetId) = if (stake) | |
102 | + | then { | |
103 | + | let $t025932659 = calcStakingFuncAndAddres(stake, assetId) | |
104 | + | let call = $t025932659._1 | |
105 | + | let stakingAddr = $t025932659._2 | |
106 | + | $Tuple4(call, stakingAddr, nil, [AttachedPayment(assetId, amount)]) | |
107 | + | } | |
108 | + | else { | |
109 | + | let $t027452811 = calcStakingFuncAndAddres(stake, assetId) | |
110 | + | let call = $t027452811._1 | |
111 | + | let stakingAddr = $t027452811._2 | |
112 | + | $Tuple4(call, stakingAddr, [amount, toBase58String(assetId)], nil) | |
113 | + | } | |
114 | + | ||
115 | + | ||
116 | + | func collectPayments (acc,payment) = { | |
117 | + | let $t029733016 = acc | |
118 | + | let paymentAmounts = $t029733016._1 | |
119 | + | let paymentAssetIds = $t029733016._2 | |
120 | + | $Tuple2((paymentAmounts :+ payment.amount), (paymentAssetIds :+ (if ((payment.assetId == unit)) | |
121 | + | then base58'' | |
122 | + | else payment.assetId))) | |
216 | 123 | } | |
217 | 124 | ||
218 | 125 | ||
219 | - | func calculateFees (pmtAmount,minAmountToReceive,tokenFrom,tokenTo,fee,feeGovernance) = { | |
220 | - | let amountWithoutFee = fraction(tokenTo, pmtAmount, (pmtAmount + tokenFrom)) | |
221 | - | let amountWithFee = fraction(amountWithoutFee, (feeScale6 - fee), feeScale6) | |
222 | - | let governanceReward = fraction(amountWithoutFee, feeGovernance, feeScale6) | |
223 | - | if ((minAmountToReceive > amountWithFee)) | |
224 | - | then throw(((("Calculated amount to receive " + toString(amountWithFee)) + " is less than specified minimum ") + toString(minAmountToReceive))) | |
225 | - | else $Tuple3(amountWithoutFee, amountWithFee, governanceReward) | |
226 | - | } | |
126 | + | func collectState (result,source) = match source { | |
127 | + | case e: Issue|Burn|Reissue|ScriptTransfer|BinaryEntry|BooleanEntry|StringEntry|IntegerEntry => | |
128 | + | (result :+ e) | |
129 | + | case _ => | |
130 | + | result | |
131 | + | } | |
227 | 132 | ||
228 | 133 | ||
229 | - | func calculateVirtPay (pmtAmount,balance,fee) = { | |
230 | - | let F = (feeScale6 - fee) | |
231 | - | let k = fraction(fee, 60, 100) | |
232 | - | let a = (scale8 + fraction((F * k), scale8, (feeScale6 * feeScale6))) | |
233 | - | let b = ((((balance + fraction(balance, F, feeScale6)) + fraction(pmtAmount, F, feeScale6)) - pmtAmount) - fraction(pmtAmount, (F * k), (feeScale6 * feeScale6))) | |
234 | - | let c = (-(toBigInt(balance)) * toBigInt(pmtAmount)) | |
235 | - | let D = ((toBigInt(b) * toBigInt(b)) - fraction((toBigInt(4) * c), toBigInt(a), toBigInt(scale8))) | |
236 | - | toInt(fraction((-(toBigInt(b)) + sqrtBigInt(D, 0, 0, DOWN)), toBigInt(scale8), toBigInt((2 * a)))) | |
237 | - | } | |
134 | + | func collectData (result,source) = match source { | |
135 | + | case v: String => | |
136 | + | (result :+ v) | |
137 | + | case v: Int => | |
138 | + | (result :+ v) | |
139 | + | case v: Boolean => | |
140 | + | (result :+ v) | |
141 | + | case v: ByteVector => | |
142 | + | (result :+ v) | |
143 | + | case v: Unit => | |
144 | + | (result :+ v) | |
145 | + | case _ => | |
146 | + | throw() | |
147 | + | } | |
238 | 148 | ||
239 | 149 | ||
240 | - | func parsePaymentAsset (assetId) = if ((assetId == base58'')) | |
241 | - | then unit | |
242 | - | else assetId | |
150 | + | func callCommon (funcName,caller,args,payments) = valueOrElse(isActive(), { | |
151 | + | let $t039364020 = { | |
152 | + | let $l = payments | |
153 | + | let $s = size($l) | |
154 | + | let $acc0 = $Tuple2(nil, nil) | |
155 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
156 | + | then $a | |
157 | + | else collectPayments($a, $l[$i]) | |
243 | 158 | ||
159 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
160 | + | then $a | |
161 | + | else throw("List size exceeds 10") | |
244 | 162 | ||
245 | - | func suspendSuspicious (accountBalanceA,accountBalanceB,balanceA,balanceB,assetIdA,assetIdB) = suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(accountBalanceA)) + " ") + assetIdA) + ", ") + toString(accountBalanceB)) + " ") + assetIdB) + ". State: ") + toString(balanceA)) + " ") + assetIdA) + ", ") + toString(balanceB)) + " ") + assetIdB)) | |
163 | + | $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) | |
164 | + | } | |
165 | + | let paymentAmounts = $t039364020._1 | |
166 | + | let paymentAssetIds = $t039364020._2 | |
167 | + | let lockPayment = if (if ((funcName == "replenishWithTwoTokens")) | |
168 | + | then (size(payments) == 3) | |
169 | + | else false) | |
170 | + | then [payments[2]] | |
171 | + | else if (if ((funcName == "replenishWithOneToken")) | |
172 | + | then (size(payments) == 2) | |
173 | + | else false) | |
174 | + | then [payments[1]] | |
175 | + | else nil | |
176 | + | let $t042494406 = { | |
177 | + | let @ = reentrantInvoke(cpmmContract, funcName, [caller, args, paymentAmounts, paymentAssetIds], lockPayment) | |
178 | + | if ($isInstanceOf(@, "(List[Any], List[Any])")) | |
179 | + | then @ | |
180 | + | else throw(($getType(@) + " couldn't be cast to (List[Any], List[Any])")) | |
181 | + | } | |
182 | + | if (($t042494406 == $t042494406)) | |
183 | + | then { | |
184 | + | let data = $t042494406._2 | |
185 | + | let actions = $t042494406._1 | |
186 | + | let mappedData = { | |
187 | + | let $l = data | |
188 | + | let $s = size($l) | |
189 | + | let $acc0 = nil | |
190 | + | func $f1_1 ($a,$i) = if (($i >= $s)) | |
191 | + | then $a | |
192 | + | else collectData($a, $l[$i]) | |
246 | 193 | ||
194 | + | func $f1_2 ($a,$i) = if (($i >= $s)) | |
195 | + | then $a | |
196 | + | else throw("List size exceeds 10") | |
247 | 197 | ||
248 | - | func isActive () = if (active) | |
249 | - | then unit | |
250 | - | else throw("DApp is inactive at this moment") | |
198 | + | $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) | |
199 | + | } | |
200 | + | let mappedActions = { | |
201 | + | let $l = actions | |
202 | + | let $s = size($l) | |
203 | + | let $acc0 = nil | |
204 | + | func $f2_1 ($a,$i) = if (($i >= $s)) | |
205 | + | then $a | |
206 | + | else collectState($a, $l[$i]) | |
251 | 207 | ||
208 | + | func $f2_2 ($a,$i) = if (($i >= $s)) | |
209 | + | then $a | |
210 | + | else throw("List size exceeds 15") | |
252 | 211 | ||
253 | - | func isOraclePool (poolAddress) = if (isDefined(getString(oracle, (kOraclePool + poolAddress)))) | |
254 | - | then unit | |
255 | - | else throw("DApp is not registered pool") | |
256 | - | ||
257 | - | ||
258 | - | func getPoolBalances (pool,assetIdA,assetIdB) = { | |
259 | - | let balanceA = getIntegerValue(pool, kBalanceA) | |
260 | - | let balanceB = getIntegerValue(pool, kBalanceB) | |
261 | - | let stakedAmountA = stakedAmount(assetIdA, pool) | |
262 | - | let stakedAmountB = stakedAmount(assetIdB, pool) | |
263 | - | let accountBalanceA = (accountBalance(assetIdA, pool) + stakedAmountA) | |
264 | - | let accountBalanceB = (accountBalance(assetIdB, pool) + stakedAmountB) | |
265 | - | let shareSupply = getIntegerValue(pool, kShareAssetSupply) | |
266 | - | $Tuple5(balanceA, balanceB, accountBalanceA, accountBalanceB, shareSupply) | |
267 | - | } | |
268 | - | ||
269 | - | ||
270 | - | func getPoolAssets (pool) = { | |
271 | - | let strAssetIdA = getStringValue(pool, kAssetIdA) | |
272 | - | let strAssetIdB = getStringValue(pool, kAssetIdB) | |
273 | - | let assetIdA = if ((strAssetIdA == "WAVES")) | |
274 | - | then unit | |
275 | - | else fromBase58String(strAssetIdA) | |
276 | - | let assetIdB = if ((strAssetIdB == "WAVES")) | |
277 | - | then unit | |
278 | - | else fromBase58String(strAssetIdB) | |
279 | - | let shareAssetId = fromBase58String(getStringValue(pool, kShareAssetId)) | |
280 | - | $Tuple5(strAssetIdA, strAssetIdB, assetIdA, assetIdB, shareAssetId) | |
281 | - | } | |
282 | - | ||
283 | - | ||
284 | - | func getFeeParams (pool,caller) = { | |
285 | - | let feeDiscount = calculateFeeDiscount(caller) | |
286 | - | let fee = fraction(getIntegerValue(pool, kFee), feeDiscount, feeScale6, CEILING) | |
287 | - | let govFee = fraction(fraction(fee, 40, 100), feeDiscount, feeScale6, CEILING) | |
288 | - | $Tuple2(fee, govFee) | |
289 | - | } | |
212 | + | $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) | |
213 | + | } | |
214 | + | $Tuple2(mappedActions, mappedData) | |
215 | + | } | |
216 | + | else throw("Strict value is not equal to itself.") | |
217 | + | }) | |
290 | 218 | ||
291 | 219 | ||
292 | 220 | @Callable(i) | |
293 | - | func init (callerBytes,args,pAmounts,pAssetIds) = { | |
294 | - | let caller = Address(callerBytes) | |
295 | - | let $t091849262 = $Tuple2(pAmounts[0], parsePaymentAsset(pAssetIds[0])) | |
296 | - | let pmtAmountA = $t091849262._1 | |
297 | - | let pmtAssetIdA = $t091849262._2 | |
298 | - | let $t092679345 = $Tuple2(pAmounts[1], parsePaymentAsset(pAssetIds[1])) | |
299 | - | let pmtAmountB = $t092679345._1 | |
300 | - | let pmtAssetIdB = $t092679345._2 | |
301 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.originCallerPublicKey))) | |
302 | - | then throw("Only admin can call this function") | |
303 | - | else if ((size(args) != 1)) | |
304 | - | then throw("Wrong args size") | |
305 | - | else if (isDefined(getBoolean(caller, kActive))) | |
306 | - | then throw("DApp is already active") | |
307 | - | else if ((pmtAssetIdA == pmtAssetIdB)) | |
308 | - | then throw("Assets must be different") | |
309 | - | else { | |
310 | - | let $t097809857 = getAssetInfo(pmtAssetIdA) | |
311 | - | let pmtStrAssetIdA = $t097809857._1 | |
312 | - | let pmtAssetNameA = $t097809857._2 | |
313 | - | let pmtDecimalsA = $t097809857._3 | |
314 | - | let $t098669943 = getAssetInfo(pmtAssetIdB) | |
315 | - | let pmtStrAssetIdB = $t098669943._1 | |
316 | - | let pmtAssetNameB = $t098669943._2 | |
317 | - | let pmtDecimalsB = $t098669943._3 | |
318 | - | let firstHarvest = (args[0] == "true") | |
319 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
320 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
321 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
322 | - | let arg1 = pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN) | |
323 | - | let arg2 = pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN) | |
324 | - | let arg3 = pow(10, 0, shareDecimals, 0, 0, DOWN) | |
325 | - | let shareInitialSupply = fraction(arg1, arg2, arg3) | |
326 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
327 | - | let shareIssueId = calculateAssetId(shareIssue) | |
328 | - | let stake1 = if (contains(stakingAssets, pmtStrAssetIdA)) | |
329 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
330 | - | else 0 | |
331 | - | if ((stake1 == stake1)) | |
332 | - | then { | |
333 | - | let stake2 = if (contains(stakingAssets, pmtStrAssetIdB)) | |
334 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
335 | - | else 0 | |
336 | - | if ((stake2 == stake2)) | |
337 | - | then { | |
338 | - | 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(caller, shareInitialSupply, shareIssueId)] | |
339 | - | if (firstHarvest) | |
340 | - | then $Tuple2(nil, $Tuple2((baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]), nil)) | |
341 | - | else $Tuple2(nil, $Tuple2(baseEntry, nil)) | |
342 | - | } | |
343 | - | else throw("Strict value is not equal to itself.") | |
344 | - | } | |
345 | - | else throw("Strict value is not equal to itself.") | |
346 | - | } | |
347 | - | } | |
221 | + | func callFunction (funcName,args) = callCommon(funcName, i.caller.bytes, args, i.payments) | |
348 | 222 | ||
349 | 223 | ||
350 | 224 | ||
351 | 225 | @Callable(i) | |
352 | - | func initWithInitRatio (callerBytes,args,pAmounts,pAssetIds) = { | |
353 | - | let caller = Address(callerBytes) | |
354 | - | let $t01216412364 = $Tuple5(parseIntValue(args[0]), parseIntValue(args[1]), args[2], args[3], (args[4] == "true")) | |
355 | - | let amtAssetA = $t01216412364._1 | |
356 | - | let amtAssetB = $t01216412364._2 | |
357 | - | let assetIdAStr = $t01216412364._3 | |
358 | - | let assetIdBStr = $t01216412364._4 | |
359 | - | let firstHarvest = $t01216412364._5 | |
360 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.originCallerPublicKey))) | |
361 | - | then throw("Only admin can call this function") | |
362 | - | else if ((size(args) != 5)) | |
363 | - | then throw("Wrong args size") | |
364 | - | else if (isDefined(getBoolean(caller, kActive))) | |
365 | - | then throw("DApp is already active") | |
366 | - | else if ((assetIdAStr == assetIdBStr)) | |
367 | - | then throw("Assets must be different") | |
368 | - | else { | |
369 | - | let $t01279912876 = getAssetInfo(assetIdAStr) | |
370 | - | let pmtStrAssetIdA = $t01279912876._1 | |
371 | - | let pmtAssetNameA = $t01279912876._2 | |
372 | - | let pmtDecimalsA = $t01279912876._3 | |
373 | - | let $t01288512962 = getAssetInfo(assetIdBStr) | |
374 | - | let pmtStrAssetIdB = $t01288512962._1 | |
375 | - | let pmtAssetNameB = $t01288512962._2 | |
376 | - | let pmtDecimalsB = $t01288512962._3 | |
377 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
378 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
379 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
380 | - | let shareInitialSupply = 0 | |
381 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
382 | - | let shareIssueId = calculateAssetId(shareIssue) | |
383 | - | 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)] | |
384 | - | if (firstHarvest) | |
385 | - | then $Tuple2(nil, $Tuple2((baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]), nil)) | |
386 | - | else $Tuple2(nil, $Tuple2(baseEntry, nil)) | |
387 | - | } | |
388 | - | } | |
226 | + | func shutdown () = valueOrElse(isAdminCall(i.callerPublicKey), if (!(active)) | |
227 | + | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, kCause), "the cause wasn't specified"))) | |
228 | + | else suspend("Paused by admin")) | |
389 | 229 | ||
390 | 230 | ||
391 | 231 | ||
392 | 232 | @Callable(i) | |
393 | - | func keepLimitForFirstHarvest (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.originCallerPublicKey))) | |
394 | - | then throw("Only admin can call this function") | |
395 | - | else if ((size(args) != 1)) | |
396 | - | then throw("Wrong args size") | |
397 | - | else { | |
398 | - | let shareLimit = parseIntValue(args[0]) | |
399 | - | $Tuple2(nil, $Tuple2([IntegerEntry(kShareLimit, shareLimit)], nil)) | |
400 | - | })) | |
233 | + | func activate () = valueOrElse(isAdminCall(i.callerPublicKey), if (active) | |
234 | + | then throw("DApp is already active") | |
235 | + | else [BooleanEntry(kActive, true), DeleteEntry(kCause)]) | |
401 | 236 | ||
402 | 237 | ||
403 | 238 | ||
404 | 239 | @Callable(i) | |
405 | - | func exchange (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
406 | - | let caller = Address(callerBytes) | |
407 | - | let $t01534815424 = $Tuple2(pAmounts[0], parsePaymentAsset(pAssetIds[0])) | |
408 | - | let pmtAmount = $t01534815424._1 | |
409 | - | let pmtAssetId = $t01534815424._2 | |
410 | - | let minAmountToReceive = parseIntValue(args[0]) | |
411 | - | let $t01549715573 = getPoolAssets(i.caller) | |
412 | - | let strAssetIdA = $t01549715573._1 | |
413 | - | let strAssetIdB = $t01549715573._2 | |
414 | - | let assetIdA = $t01549715573._3 | |
415 | - | let assetIdB = $t01549715573._4 | |
416 | - | let $t01558615692 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
417 | - | let balanceA = $t01558615692._1 | |
418 | - | let balanceB = $t01558615692._2 | |
419 | - | let accountBalanceA = $t01558615692._3 | |
420 | - | let accountBalanceB = $t01558615692._4 | |
421 | - | if ((size(args) != 1)) | |
422 | - | then throw("Wrong args size") | |
423 | - | else if (if ((balanceA == 0)) | |
424 | - | then true | |
425 | - | else (balanceB == 0)) | |
426 | - | then throw("Can't exchange with zero balance") | |
427 | - | else if ((0 >= minAmountToReceive)) | |
428 | - | then throw(("Minimal amount to receive must be positive. Actual: " + toString(minAmountToReceive))) | |
429 | - | else if ((size(pAmounts) != 1)) | |
430 | - | then throw("One attached payment expected") | |
431 | - | else if (!(containsElement([assetIdA, assetIdB], pmtAssetId))) | |
432 | - | then throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
433 | - | else if (if ((balanceA > accountBalanceA)) | |
434 | - | then true | |
435 | - | else (balanceB > accountBalanceB)) | |
436 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))) | |
437 | - | else { | |
438 | - | let $t01666016718 = getFeeParams(i.caller, i.originCaller) | |
439 | - | let fee = $t01666016718._1 | |
440 | - | let govFee = $t01666016718._2 | |
441 | - | let $t01673517072 = if ((pmtAssetId == assetIdA)) | |
442 | - | then calculateFees(pmtAmount, minAmountToReceive, balanceA, balanceB, fee, govFee) | |
443 | - | else calculateFees(pmtAmount, minAmountToReceive, balanceB, balanceA, fee, govFee) | |
444 | - | let amountWithoutFee = $t01673517072._1 | |
445 | - | let amountWithFee = $t01673517072._2 | |
446 | - | let governanceReward = $t01673517072._3 | |
447 | - | let $t01709017415 = if ((pmtAssetId == assetIdA)) | |
448 | - | then $Tuple3((balanceA + pmtAmount), ((balanceB - amountWithFee) - governanceReward), assetIdB) | |
449 | - | else $Tuple3(((balanceA - amountWithFee) - governanceReward), (balanceB + pmtAmount), assetIdA) | |
450 | - | let newBalanceA = $t01709017415._1 | |
451 | - | let newBalanceB = $t01709017415._2 | |
452 | - | let assetIdSend = $t01709017415._3 | |
453 | - | let $t01743317683 = if ((pmtAssetId == assetIdA)) | |
454 | - | then $Tuple2(pmtAmount, (amountWithFee + governanceReward)) | |
455 | - | else $Tuple2((amountWithFee + governanceReward), pmtAmount) | |
456 | - | let stakeAmountA = $t01743317683._1 | |
457 | - | let stakeAmountB = $t01743317683._2 | |
458 | - | let stake1 = if (contains(stakingAssets, strAssetIdA)) | |
459 | - | then invoke(i.caller, "stakeUnstake", [(pmtAssetId == assetIdA), stakeAmountA, strAssetIdA], nil) | |
460 | - | else 0 | |
461 | - | if ((stake1 == stake1)) | |
462 | - | then { | |
463 | - | let stake2 = if (contains(stakingAssets, strAssetIdB)) | |
464 | - | then invoke(i.caller, "stakeUnstake", [(pmtAssetId == assetIdB), stakeAmountB, strAssetIdB], nil) | |
465 | - | else 0 | |
466 | - | if ((stake2 == stake2)) | |
467 | - | then $Tuple2(nil, $Tuple2([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), ScriptTransfer(caller, amountWithFee, assetIdSend), ScriptTransfer(moneyBoxAddress, governanceReward, assetIdSend)], [amountWithFee, assetIdSend])) | |
468 | - | else throw("Strict value is not equal to itself.") | |
469 | - | } | |
470 | - | else throw("Strict value is not equal to itself.") | |
471 | - | } | |
240 | + | func stakeUnstake (stake,amount,assetIdString) = valueOrElse(isActive(), if ((i.caller != cpmmContract)) | |
241 | + | then throw("Only global Contract can invoke this function") | |
242 | + | else if ((assetIdString == "WAVES")) | |
243 | + | then { | |
244 | + | let pool = addressFromStringValue(valueOrErrorMessage(getString(oracle, kLeasingPool), "No leasing pool in oracle")) | |
245 | + | let leasingId = getBinary(this, kLeasingId) | |
246 | + | let leasingAmount = valueOrElse(getInteger(this, kLeasingAmount), 0) | |
247 | + | let newLeaseAmount = if (stake) | |
248 | + | then (leasingAmount + amount) | |
249 | + | else (leasingAmount - amount) | |
250 | + | let newLease = Lease(pool, newLeaseAmount) | |
251 | + | let newLeaseId = calculateLeaseId(newLease) | |
252 | + | let baseEtry = [newLease, BinaryEntry(kLeasingId, newLeaseId), IntegerEntry(kLeasingAmount, newLeaseAmount)] | |
253 | + | match leasingId { | |
254 | + | case lId: ByteVector => | |
255 | + | ([LeaseCancel(lId)] ++ baseEtry) | |
256 | + | case _ => | |
257 | + | baseEtry | |
258 | + | } | |
259 | + | } | |
260 | + | else { | |
261 | + | let $t064026505 = calcStakingParams(stake, amount, fromBase58String(assetIdString)) | |
262 | + | let call = $t064026505._1 | |
263 | + | let addr = $t064026505._2 | |
264 | + | let params = $t064026505._3 | |
265 | + | let payments = $t064026505._4 | |
266 | + | let inv = invoke(addr, call, params, payments) | |
267 | + | if ((inv == inv)) | |
268 | + | then nil | |
269 | + | else throw("Strict value is not equal to itself.") | |
270 | + | }) | |
271 | + | ||
272 | + | ||
273 | + | ||
274 | + | @Callable(i) | |
275 | + | func reissueShareToken (amount) = valueOrElse(isGlobalCaller(i.caller), valueOrElse(isActive(), { | |
276 | + | let shareAssetId = fromBase58String(getStringValue(this, kShareAssetId)) | |
277 | + | [Reissue(shareAssetId, amount, true), ScriptTransfer(i.caller, amount, shareAssetId)] | |
472 | 278 | })) | |
473 | 279 | ||
474 | 280 | ||
475 | 281 | ||
476 | 282 | @Callable(i) | |
477 | - | func replenishWithTwoTokens (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
478 | - | let caller = Address(callerBytes) | |
479 | - | let pmtAssetIdA = parsePaymentAsset(pAssetIds[0]) | |
480 | - | let pmtAssetIdB = parsePaymentAsset(pAssetIds[1]) | |
481 | - | let stakeFarming = (args[0] == "true") | |
482 | - | let lockType = parseIntValue(args[1]) | |
483 | - | let $t01894619036 = getPoolAssets(i.caller) | |
484 | - | let strAssetIdA = $t01894619036._1 | |
485 | - | let strAssetIdB = $t01894619036._2 | |
486 | - | let assetIdA = $t01894619036._3 | |
487 | - | let assetIdB = $t01894619036._4 | |
488 | - | let shareAssetId = $t01894619036._5 | |
489 | - | let $t01904919173 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
490 | - | let balanceA = $t01904919173._1 | |
491 | - | let balanceB = $t01904919173._2 | |
492 | - | let accountBalanceA = $t01904919173._3 | |
493 | - | let accountBalanceB = $t01904919173._4 | |
494 | - | let shareAssetSupply = $t01904919173._5 | |
495 | - | if ((size(args) != 2)) | |
496 | - | then throw("Wrong args size") | |
497 | - | else if (if ((size(pAmounts) != 2)) | |
498 | - | then (size(pAmounts) != 3) | |
499 | - | else false) | |
500 | - | then throw("Two or three payments expected") | |
501 | - | else if (if ((pmtAssetIdA != assetIdA)) | |
502 | - | then true | |
503 | - | else (pmtAssetIdB != assetIdB)) | |
504 | - | then throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
505 | - | else if (if ((balanceA > accountBalanceA)) | |
506 | - | then true | |
507 | - | else (balanceB > accountBalanceB)) | |
508 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pAmounts[0], pmtAssetIdA), ScriptTransfer(caller, pAmounts[1], pmtAssetIdB)] ++ (if ((size(pAmounts) == 3)) | |
509 | - | then [AttachedPayment(if ((pAssetIds[2] == base58'')) | |
510 | - | then unit | |
511 | - | else pAssetIds[2], pAmounts[2])] | |
512 | - | else (nil ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))))) | |
513 | - | else { | |
514 | - | let $t02017420251 = getAssetInfo(pmtAssetIdA) | |
515 | - | let pmtStrAssetIdA = $t02017420251._1 | |
516 | - | let pmtAssetNameA = $t02017420251._2 | |
517 | - | let pmtDecimalsA = $t02017420251._3 | |
518 | - | let $t02026820345 = getAssetInfo(pmtAssetIdB) | |
519 | - | let pmtStrAssetIdB = $t02026820345._1 | |
520 | - | let pmtAssetNameB = $t02026820345._2 | |
521 | - | let pmtDecimalsB = $t02026820345._3 | |
522 | - | let initial = ((balanceA + balanceB) == 0) | |
523 | - | let $t02042021263 = if (initial) | |
524 | - | then $Tuple5(pAmounts[0], pAmounts[1], 0, pmtAssetIdA, 1) | |
525 | - | else { | |
526 | - | let ratioShareTokensInA = fraction(scale8, pAmounts[0], balanceA) | |
527 | - | let ratioShareTokensInB = fraction(scale8, pAmounts[1], balanceB) | |
528 | - | if ((ratioShareTokensInB > ratioShareTokensInA)) | |
529 | - | then { | |
530 | - | let pmt = fraction(pAmounts[0], balanceB, balanceA) | |
531 | - | $Tuple5(pAmounts[0], pmt, (pAmounts[1] - pmt), pmtAssetIdB, ratioShareTokensInA) | |
532 | - | } | |
533 | - | else { | |
534 | - | let pmt = fraction(pAmounts[1], balanceA, balanceB) | |
535 | - | $Tuple5(pmt, pAmounts[1], (pAmounts[0] - pmt), pmtAssetIdA, ratioShareTokensInB) | |
536 | - | } | |
537 | - | } | |
538 | - | let pmtAmountA = $t02042021263._1 | |
539 | - | let pmtAmountB = $t02042021263._2 | |
540 | - | let change = $t02042021263._3 | |
541 | - | let changeAssetId = $t02042021263._4 | |
542 | - | let shareTokenRatio = $t02042021263._5 | |
543 | - | let shareTokenToPayAmount = if (initial) | |
544 | - | then { | |
545 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
546 | - | fraction(pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN), pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN), pow(10, 0, shareDecimals, 0, 0, DOWN)) | |
547 | - | } | |
548 | - | else fraction(shareTokenRatio, shareAssetSupply, scale8) | |
549 | - | if ((shareTokenToPayAmount == 0)) | |
550 | - | then throw("Too small amount to replenish") | |
551 | - | else if ((0 > change)) | |
552 | - | then throw("Change < 0") | |
553 | - | else { | |
554 | - | let stake1 = if (contains(stakingAssets, pmtStrAssetIdA)) | |
555 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
556 | - | else 0 | |
557 | - | if ((stake1 == stake1)) | |
558 | - | then { | |
559 | - | let stake2 = if (contains(stakingAssets, pmtStrAssetIdB)) | |
560 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
561 | - | else 0 | |
562 | - | if ((stake2 == stake2)) | |
563 | - | then { | |
564 | - | let shareTokenST = if (stakeFarming) | |
565 | - | then { | |
566 | - | let stPayments = ([AttachedPayment(shareAssetId, shareTokenToPayAmount)] ++ (if ((size(pAmounts) == 3)) | |
567 | - | then [AttachedPayment(if ((pAssetIds[2] == base58'')) | |
568 | - | then unit | |
569 | - | else pAssetIds[2], pAmounts[2])] | |
570 | - | else nil)) | |
571 | - | let reissue = invoke(i.caller, "reissueShareToken", [shareTokenToPayAmount], nil) | |
572 | - | if ((reissue == reissue)) | |
573 | - | then { | |
574 | - | let stake3 = invoke(farmingAddress, "lockShareTokensFromPool", [callerBytes, toString(i.caller), lockType], stPayments) | |
575 | - | if ((stake3 == stake3)) | |
576 | - | then nil | |
577 | - | else throw("Strict value is not equal to itself.") | |
578 | - | } | |
579 | - | else throw("Strict value is not equal to itself.") | |
580 | - | } | |
581 | - | else [Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(caller, shareTokenToPayAmount, shareAssetId)] | |
582 | - | $Tuple2(nil, $Tuple2(([IntegerEntry(kBalanceA, (balanceA + pmtAmountA)), IntegerEntry(kBalanceB, (balanceB + pmtAmountB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), ScriptTransfer(caller, change, changeAssetId)] ++ shareTokenST), nil)) | |
583 | - | } | |
584 | - | else throw("Strict value is not equal to itself.") | |
585 | - | } | |
586 | - | else throw("Strict value is not equal to itself.") | |
587 | - | } | |
588 | - | } | |
589 | - | })) | |
283 | + | func replenishWithTwoTokens (slippageTolerance) = callCommon("replenishWithTwoTokens", i.caller.bytes, ["false", "0"], i.payments) | |
590 | 284 | ||
591 | 285 | ||
592 | 286 | ||
593 | 287 | @Callable(i) | |
594 | - | func replenishWithOneToken (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
595 | - | let caller = Address(callerBytes) | |
596 | - | let pmtAssetId = parsePaymentAsset(pAssetIds[0]) | |
597 | - | let pmtAmount = pAmounts[0] | |
598 | - | let virtGetMinAmount = parseIntValue(args[0]) | |
599 | - | let stakeFarming = (args[1] == "true") | |
600 | - | let lockType = parseIntValue(args[2]) | |
601 | - | let $t02416824258 = getPoolAssets(i.caller) | |
602 | - | let strAssetIdA = $t02416824258._1 | |
603 | - | let strAssetIdB = $t02416824258._2 | |
604 | - | let assetIdA = $t02416824258._3 | |
605 | - | let assetIdB = $t02416824258._4 | |
606 | - | let shareAssetId = $t02416824258._5 | |
607 | - | let $t02427124395 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
608 | - | let balanceA = $t02427124395._1 | |
609 | - | let balanceB = $t02427124395._2 | |
610 | - | let accountBalanceA = $t02427124395._3 | |
611 | - | let accountBalanceB = $t02427124395._4 | |
612 | - | let shareAssetSupply = $t02427124395._5 | |
613 | - | let initial = ((balanceA + balanceB) == 0) | |
614 | - | if ((size(args) != 3)) | |
615 | - | then throw("Wrong args size") | |
616 | - | else if (if ((size(pAmounts) != 1)) | |
617 | - | then (size(pAmounts) != 2) | |
618 | - | else false) | |
619 | - | then throw("Two or one attached assets expected") | |
620 | - | else if (if ((pmtAssetId != assetIdA)) | |
621 | - | then (pmtAssetId != assetIdB) | |
622 | - | else false) | |
623 | - | then throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
624 | - | else if (initial) | |
625 | - | then throw("For initial exchanger you need to use two tokens") | |
626 | - | else if (if ((balanceA > accountBalanceA)) | |
627 | - | then true | |
628 | - | else (balanceB > accountBalanceB)) | |
629 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ (if ((size(pAmounts) == 2)) | |
630 | - | then [AttachedPayment(if ((pAssetIds[2] == base58'')) | |
631 | - | then unit | |
632 | - | else pAssetIds[2], pAmounts[2])] | |
633 | - | else (nil ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))))) | |
634 | - | else { | |
635 | - | let $t02545125509 = getFeeParams(i.caller, i.originCaller) | |
636 | - | let fee = $t02545125509._1 | |
637 | - | let govFee = $t02545125509._2 | |
638 | - | let $t02552627732 = if ((pmtAssetId == assetIdA)) | |
639 | - | then { | |
640 | - | let virtPayAmount = calculateVirtPay(pmtAmount, balanceA, fee) | |
641 | - | let $t02580525942 = calculateFees(virtPayAmount, virtGetMinAmount, balanceA, balanceB, fee, govFee) | |
642 | - | let amountWithoutFee = $t02580525942._1 | |
643 | - | let amountWithFee = $t02580525942._2 | |
644 | - | let governanceReward = $t02580525942._3 | |
645 | - | let balanceAVirt = (balanceA + virtPayAmount) | |
646 | - | let balanceBVirt = ((balanceB + amountWithoutFee) - governanceReward) | |
647 | - | let newBalanceA = (balanceA + pmtAmount) | |
648 | - | let newBalanceB = (balanceB - governanceReward) | |
649 | - | let ratioShareTokensInA = fraction((pmtAmount - virtPayAmount), scale8, balanceAVirt) | |
650 | - | let ratioShareTokensInB = fraction(amountWithFee, scale8, balanceBVirt) | |
651 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
652 | - | $Tuple7(newBalanceA, newBalanceB, shareTokenToPayAmount, governanceReward, assetIdB, strAssetIdB, strAssetIdA) | |
653 | - | } | |
654 | - | else { | |
655 | - | let virtPayAmount = calculateVirtPay(pmtAmount, balanceB, fee) | |
656 | - | let $t02683726974 = calculateFees(virtPayAmount, virtGetMinAmount, balanceB, balanceA, fee, govFee) | |
657 | - | let amountWithoutFee = $t02683726974._1 | |
658 | - | let amountWithFee = $t02683726974._2 | |
659 | - | let governanceReward = $t02683726974._3 | |
660 | - | let balanceAVirt = ((balanceA + amountWithoutFee) - governanceReward) | |
661 | - | let balanceBVirt = (balanceB + virtPayAmount) | |
662 | - | let newBalanceA = (balanceA - governanceReward) | |
663 | - | let newBalanceB = (balanceB + pmtAmount) | |
664 | - | let ratioShareTokensInA = fraction(amountWithFee, scale8, balanceAVirt) | |
665 | - | let ratioShareTokensInB = fraction((pmtAmount - virtPayAmount), scale8, balanceBVirt) | |
666 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
667 | - | $Tuple7(newBalanceA, newBalanceB, shareTokenToPayAmount, governanceReward, assetIdA, strAssetIdA, strAssetIdB) | |
668 | - | } | |
669 | - | let newBalanceA = $t02552627732._1 | |
670 | - | let newBalanceB = $t02552627732._2 | |
671 | - | let shareTokenToPayAmount = $t02552627732._3 | |
672 | - | let govReward = $t02552627732._4 | |
673 | - | let govRewardAsset = $t02552627732._5 | |
674 | - | let govRewardAssetStr = $t02552627732._6 | |
675 | - | let pmtAssetIdStr = $t02552627732._7 | |
676 | - | if ((shareTokenToPayAmount == 0)) | |
677 | - | then throw("Too small amount to replenish") | |
678 | - | else { | |
679 | - | let stake1 = if (contains(stakingAssets, pmtAssetIdStr)) | |
680 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmount, pmtAssetIdStr], nil) | |
681 | - | else 0 | |
682 | - | if ((stake1 == stake1)) | |
683 | - | then { | |
684 | - | let stake2 = if (contains(stakingAssets, govRewardAssetStr)) | |
685 | - | then invoke(i.caller, "stakeUnstake", [false, govReward, govRewardAssetStr], nil) | |
686 | - | else 0 | |
687 | - | if ((stake2 == stake2)) | |
688 | - | then { | |
689 | - | let shareTokenST = if (stakeFarming) | |
690 | - | then { | |
691 | - | let stPayments = ([AttachedPayment(shareAssetId, shareTokenToPayAmount)] ++ (if ((size(pAmounts) == 2)) | |
692 | - | then [AttachedPayment(if ((pAssetIds[1] == base58'')) | |
693 | - | then unit | |
694 | - | else pAssetIds[1], pAmounts[1])] | |
695 | - | else nil)) | |
696 | - | let reissue = invoke(i.caller, "reissueShareToken", [shareTokenToPayAmount], nil) | |
697 | - | if ((reissue == reissue)) | |
698 | - | then { | |
699 | - | let stake3 = invoke(farmingAddress, "lockShareTokensFromPool", [callerBytes, toString(i.caller), lockType], stPayments) | |
700 | - | if ((stake3 == stake3)) | |
701 | - | then nil | |
702 | - | else throw("Strict value is not equal to itself.") | |
703 | - | } | |
704 | - | else throw("Strict value is not equal to itself.") | |
705 | - | } | |
706 | - | else [Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(caller, shareTokenToPayAmount, shareAssetId)] | |
707 | - | $Tuple2(nil, $Tuple2(([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), ScriptTransfer(moneyBoxAddress, govReward, govRewardAsset)] ++ shareTokenST), nil)) | |
708 | - | } | |
709 | - | else throw("Strict value is not equal to itself.") | |
710 | - | } | |
711 | - | else throw("Strict value is not equal to itself.") | |
712 | - | } | |
713 | - | } | |
714 | - | })) | |
288 | + | func withdraw () = callCommon("withdraw", i.caller.bytes, ["0"], i.payments) | |
715 | 289 | ||
716 | 290 | ||
717 | 291 | ||
718 | 292 | @Callable(i) | |
719 | - | func withdraw (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
720 | - | let time = lastBlock.timestamp | |
721 | - | let caller = Address(callerBytes) | |
722 | - | let $t02988629976 = getPoolAssets(i.caller) | |
723 | - | let strAssetIdA = $t02988629976._1 | |
724 | - | let strAssetIdB = $t02988629976._2 | |
725 | - | let assetIdA = $t02988629976._3 | |
726 | - | let assetIdB = $t02988629976._4 | |
727 | - | let shareAssetId = $t02988629976._5 | |
728 | - | let $t02998930113 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
729 | - | let balanceA = $t02998930113._1 | |
730 | - | let balanceB = $t02998930113._2 | |
731 | - | let accountBalanceA = $t02998930113._3 | |
732 | - | let accountBalanceB = $t02998930113._4 | |
733 | - | let shareAssetSupply = $t02998930113._5 | |
734 | - | let $t03012630534 = if ((size(pAmounts) == 1)) | |
735 | - | then { | |
736 | - | let pAsset = parsePaymentAsset(pAssetIds[0]) | |
737 | - | if ((pAsset != shareAssetId)) | |
738 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
739 | - | else $Tuple2(pAmounts[0], pAsset) | |
740 | - | } | |
741 | - | else $Tuple2(0, shareAssetId) | |
742 | - | let pmtAmount = $t03012630534._1 | |
743 | - | let pmtAssetId = $t03012630534._2 | |
744 | - | if ((size(args) != 1)) | |
745 | - | then throw("Wrong args size") | |
746 | - | else if ((size(pAmounts) > 1)) | |
747 | - | then throw("One attached payment expected") | |
748 | - | else if (if ((balanceA > accountBalanceA)) | |
749 | - | then true | |
750 | - | else (balanceB > accountBalanceB)) | |
751 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))) | |
752 | - | else { | |
753 | - | let unlockAmount = parseIntValue(valueOrElse(args[0], "0")) | |
754 | - | let unlock = if ((unlockAmount > 0)) | |
755 | - | then invoke(farmingAddress, "withdrawShareTokensFromPool", [callerBytes, toString(i.caller), unlockAmount], nil) | |
756 | - | else 0 | |
757 | - | if ((unlock == unlock)) | |
758 | - | then { | |
759 | - | let withdrawAmount = (pmtAmount + unlockAmount) | |
760 | - | let amountToPayA = fraction(withdrawAmount, balanceA, shareAssetSupply) | |
761 | - | let amountToPayB = fraction(withdrawAmount, balanceB, shareAssetSupply) | |
762 | - | let stake1 = if (contains(stakingAssets, strAssetIdA)) | |
763 | - | then invoke(i.caller, "stakeUnstake", [false, amountToPayA, strAssetIdA], nil) | |
764 | - | else 0 | |
765 | - | if ((stake1 == stake1)) | |
766 | - | then { | |
767 | - | let stake2 = if (contains(stakingAssets, strAssetIdB)) | |
768 | - | then invoke(i.caller, "stakeUnstake", [false, amountToPayB, strAssetIdB], nil) | |
769 | - | else 0 | |
770 | - | if ((stake2 == stake2)) | |
771 | - | then $Tuple2([ScriptTransfer(i.caller, unlockAmount, shareAssetId)], $Tuple2([IntegerEntry(kBalanceA, (balanceA - amountToPayA)), IntegerEntry(kBalanceB, (balanceB - amountToPayB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply - withdrawAmount)), Burn(shareAssetId, withdrawAmount), ScriptTransfer(caller, amountToPayA, assetIdA), ScriptTransfer(caller, amountToPayB, assetIdB)], nil)) | |
772 | - | else throw("Strict value is not equal to itself.") | |
773 | - | } | |
774 | - | else throw("Strict value is not equal to itself.") | |
775 | - | } | |
776 | - | else throw("Strict value is not equal to itself.") | |
777 | - | } | |
778 | - | })) | |
779 | - | ||
780 | - | ||
781 | - | ||
782 | - | @Callable(i) | |
783 | - | func withdrawOneToken (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
784 | - | let caller = Address(callerBytes) | |
785 | - | let withdrawAsset = if ((args[0] == "")) | |
786 | - | then unit | |
787 | - | else fromBase58String(args[0]) | |
788 | - | let $t03284532935 = getPoolAssets(i.caller) | |
789 | - | let strAssetIdA = $t03284532935._1 | |
790 | - | let strAssetIdB = $t03284532935._2 | |
791 | - | let assetIdA = $t03284532935._3 | |
792 | - | let assetIdB = $t03284532935._4 | |
793 | - | let shareAssetId = $t03284532935._5 | |
794 | - | let $t03294833072 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
795 | - | let balanceA = $t03294833072._1 | |
796 | - | let balanceB = $t03294833072._2 | |
797 | - | let accountBalanceA = $t03294833072._3 | |
798 | - | let accountBalanceB = $t03294833072._4 | |
799 | - | let shareAssetSupply = $t03294833072._5 | |
800 | - | let $t03308533465 = if ((size(pAmounts) == 1)) | |
801 | - | then { | |
802 | - | let pAsset = parsePaymentAsset(pAssetIds[0]) | |
803 | - | if ((pAsset != shareAssetId)) | |
804 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
805 | - | else $Tuple2(pAmounts[0], pAsset) | |
806 | - | } | |
807 | - | else $Tuple2(0, shareAssetId) | |
808 | - | let pmtAmount = $t03308533465._1 | |
809 | - | let pmtAssetId = $t03308533465._2 | |
810 | - | let virtMinToRecive = parseIntValue(args[1]) | |
811 | - | if ((size(args) != 3)) | |
812 | - | then throw("Wrong args size") | |
813 | - | else if ((size(pAmounts) > 1)) | |
814 | - | then throw("One attached payment expected") | |
815 | - | else if ((pmtAssetId != shareAssetId)) | |
816 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
817 | - | else if (!(containsElement([assetIdA, assetIdB], withdrawAsset))) | |
818 | - | then throw("Incorrect withdraw asset.") | |
819 | - | else if (if ((balanceA > accountBalanceA)) | |
820 | - | then true | |
821 | - | else (balanceB > accountBalanceB)) | |
822 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))) | |
823 | - | else { | |
824 | - | let unlockAmount = parseIntValue(valueOrElse(args[2], "0")) | |
825 | - | let unlock = if ((unlockAmount > 0)) | |
826 | - | then invoke(farmingAddress, "withdrawShareTokensFromPool", [callerBytes, toString(i.caller), unlockAmount], nil) | |
827 | - | else 0 | |
828 | - | if ((unlock == unlock)) | |
829 | - | then { | |
830 | - | let withdrawAmount = (pmtAmount + unlockAmount) | |
831 | - | let amountToPayA = fraction(withdrawAmount, balanceA, shareAssetSupply) | |
832 | - | let amountToPayB = fraction(withdrawAmount, balanceB, shareAssetSupply) | |
833 | - | let $t03481334871 = getFeeParams(i.caller, i.originCaller) | |
834 | - | let fee = $t03481334871._1 | |
835 | - | let govFee = $t03481334871._2 | |
836 | - | let $t03488835288 = if ((withdrawAsset == assetIdA)) | |
837 | - | then calculateFees(amountToPayB, virtMinToRecive, (balanceB - amountToPayB), (balanceA - amountToPayA), fee, govFee) | |
838 | - | else calculateFees(amountToPayA, virtMinToRecive, (balanceA - amountToPayA), (balanceB - amountToPayB), fee, govFee) | |
839 | - | let amountWithoutFee = $t03488835288._1 | |
840 | - | let amountWithFee = $t03488835288._2 | |
841 | - | let governanceReward = $t03488835288._3 | |
842 | - | let $t03530536651 = if ((withdrawAsset == assetIdA)) | |
843 | - | then { | |
844 | - | let unstake = if (contains(stakingAssets, strAssetIdA)) | |
845 | - | then invoke(i.caller, "stakeUnstake", [false, ((amountToPayA + amountWithFee) + governanceReward), strAssetIdA], nil) | |
846 | - | else 0 | |
847 | - | if ((unstake == unstake)) | |
848 | - | then $Tuple4((((balanceA - amountToPayA) - amountWithFee) - governanceReward), balanceB, assetIdA, [ScriptTransfer(caller, (amountToPayA + amountWithFee), assetIdA)]) | |
849 | - | else throw("Strict value is not equal to itself.") | |
850 | - | } | |
851 | - | else { | |
852 | - | let unstake = if (contains(stakingAssets, strAssetIdB)) | |
853 | - | then invoke(i.caller, "stakeUnstake", [false, ((amountToPayB + amountWithFee) + governanceReward), strAssetIdB], nil) | |
854 | - | else 0 | |
855 | - | if ((unstake == unstake)) | |
856 | - | then $Tuple4(balanceA, (((balanceB - amountToPayB) - amountWithFee) - governanceReward), assetIdB, [ScriptTransfer(caller, (amountToPayB + amountWithFee), assetIdB)]) | |
857 | - | else throw("Strict value is not equal to itself.") | |
858 | - | } | |
859 | - | let newBalanceA = $t03530536651._1 | |
860 | - | let newBalanceB = $t03530536651._2 | |
861 | - | let govRewardAssetId = $t03530536651._3 | |
862 | - | let userTransfer = $t03530536651._4 | |
863 | - | $Tuple2([ScriptTransfer(i.caller, unlockAmount, shareAssetId)], $Tuple2(([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), IntegerEntry(kShareAssetSupply, (shareAssetSupply - withdrawAmount)), Burn(shareAssetId, withdrawAmount), ScriptTransfer(moneyBoxAddress, governanceReward, govRewardAssetId)] ++ userTransfer), nil)) | |
864 | - | } | |
865 | - | else throw("Strict value is not equal to itself.") | |
866 | - | } | |
867 | - | })) | |
868 | - | ||
869 | - | ||
870 | - | ||
871 | - | @Callable(i) | |
872 | - | func takeIntoAccountExtraFunds (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
873 | - | let $t03737637452 = getPoolAssets(i.caller) | |
874 | - | let strAssetIdA = $t03737637452._1 | |
875 | - | let strAssetIdB = $t03737637452._2 | |
876 | - | let assetIdA = $t03737637452._3 | |
877 | - | let assetIdB = $t03737637452._4 | |
878 | - | let $t03746537571 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
879 | - | let balanceA = $t03746537571._1 | |
880 | - | let balanceB = $t03746537571._2 | |
881 | - | let accountBalanceA = $t03746537571._3 | |
882 | - | let accountBalanceB = $t03746537571._4 | |
883 | - | let amountEnrollA = (accountBalanceA - balanceA) | |
884 | - | let amountEnrollB = (accountBalanceB - balanceB) | |
885 | - | if ((size(args) != 0)) | |
886 | - | then throw("Wrong args size") | |
887 | - | else if ((moneyBoxAddress != i.originCaller)) | |
888 | - | then throw("Only the wallet can call this function") | |
889 | - | else if (if ((0 > amountEnrollA)) | |
890 | - | then true | |
891 | - | else (0 > amountEnrollB)) | |
892 | - | then suspend("Enroll amount negative") | |
893 | - | else if (if ((amountEnrollA == 0)) | |
894 | - | then (amountEnrollB == 0) | |
895 | - | else false) | |
896 | - | then throw("No money to take") | |
897 | - | else { | |
898 | - | let stake1 = if (if (contains(stakingAssets, strAssetIdA)) | |
899 | - | then (amountEnrollA > 0) | |
900 | - | else false) | |
901 | - | then invoke(i.caller, "stakeUnstake", [true, amountEnrollA, strAssetIdA], nil) | |
902 | - | else 0 | |
903 | - | if ((stake1 == stake1)) | |
904 | - | then { | |
905 | - | let stake2 = if (if (contains(stakingAssets, strAssetIdB)) | |
906 | - | then (amountEnrollB > 0) | |
907 | - | else false) | |
908 | - | then invoke(i.caller, "stakeUnstake", [true, amountEnrollB, strAssetIdB], nil) | |
909 | - | else 0 | |
910 | - | if ((stake2 == stake2)) | |
911 | - | then $Tuple2(nil, $Tuple2([IntegerEntry(kBalanceA, (balanceA + amountEnrollA)), IntegerEntry(kBalanceB, (balanceB + amountEnrollB))], nil)) | |
912 | - | else throw("Strict value is not equal to itself.") | |
913 | - | } | |
914 | - | else throw("Strict value is not equal to itself.") | |
915 | - | } | |
916 | - | })) | |
293 | + | func exchange (minAmountToReceive) = callCommon("exchange", i.caller.bytes, [toString(minAmountToReceive)], i.payments) | |
917 | 294 | ||
918 | 295 | ||
919 | 296 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | 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" | |
6 | + | let kActiveGlob = "active_all_contracts" | |
27 | 7 | ||
28 | 8 | 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 | 9 | ||
42 | 10 | let kUSDNAddress = "staking_usdnnsbt_address" | |
43 | 11 | ||
44 | 12 | let kEURNAddress = "staking_eurn_address" | |
45 | 13 | ||
14 | + | let kLeasingPool = "leasing_address" | |
15 | + | ||
46 | 16 | let kLeasingAmount = "leasing_amount" | |
47 | 17 | ||
48 | - | let kUSDNAssetId = "usdn_asset_id" | |
49 | - | ||
50 | - | let kEURNAssetId = "eurn_asset_id" | |
51 | - | ||
52 | - | let kStakingAssets = "staking_assets" | |
53 | - | ||
54 | - | let kOracleActive = "active_all_contracts" | |
55 | - | ||
56 | - | let kOracleActiveExchangers = "active_global_exchangers" | |
57 | - | ||
58 | - | let kDiscounts = "discounts" | |
59 | - | ||
60 | - | let kDiscountValues = "discount_values" | |
61 | - | ||
62 | - | let kUserGSwopInGov = "_GSwop_amount" | |
63 | - | ||
64 | - | let kUserSwopInGov = "_SWOP_amount" | |
65 | - | ||
66 | - | let kOraclePool = "pool_" | |
18 | + | let kLeasingId = "leasing_id" | |
67 | 19 | ||
68 | 20 | let kAdminPubKey1 = "admin_pub_1" | |
69 | 21 | ||
70 | 22 | let kAdminPubKey2 = "admin_pub_2" | |
71 | 23 | ||
72 | 24 | let kAdminPubKey3 = "admin_pub_3" | |
73 | 25 | ||
74 | 26 | let kAdminInvokePubKey = "admin_invoke_pub" | |
75 | 27 | ||
76 | - | let | |
28 | + | let kCpmmContract = "cpmm_contract" | |
77 | 29 | ||
78 | - | let | |
30 | + | let kUSDNAssetId = "usdn_asset_id" | |
79 | 31 | ||
80 | - | let | |
32 | + | let kEURNAssetId = "eurn_asset_id" | |
81 | 33 | ||
82 | - | let kFarmingAddress = "farming_address" | |
34 | + | let kStakingAssets = "staking_assets" | |
35 | + | ||
36 | + | let kShareAssetId = "share_asset_id" | |
83 | 37 | ||
84 | 38 | let oracle = Address(base58'3MvVBtsXroQpy1tsPw21TU2ET9A8WfmrNjz') | |
85 | 39 | ||
86 | 40 | func getBase58FromOracle (key) = match getString(oracle, key) { | |
87 | 41 | case string: String => | |
88 | 42 | fromBase58String(string) | |
89 | 43 | case nothing => | |
90 | 44 | throw((key + "is empty")) | |
91 | 45 | } | |
92 | 46 | ||
93 | 47 | ||
94 | 48 | let adminPubKey1 = getBase58FromOracle(kAdminPubKey1) | |
95 | 49 | ||
96 | 50 | let adminPubKey2 = getBase58FromOracle(kAdminPubKey2) | |
97 | 51 | ||
98 | 52 | let adminPubKey3 = getBase58FromOracle(kAdminPubKey3) | |
99 | 53 | ||
100 | - | let | |
54 | + | let adminPubKeyInvoke = getBase58FromOracle(kAdminInvokePubKey) | |
101 | 55 | ||
102 | - | let | |
56 | + | let stakingUSDNAddress = Address(getBase58FromOracle(kUSDNAddress)) | |
103 | 57 | ||
104 | - | let | |
58 | + | let stakingEURNAddress = Address(getBase58FromOracle(kEURNAddress)) | |
105 | 59 | ||
106 | - | let govAddress = Address(getBase58FromOracle(kGovAddress)) | |
107 | - | ||
108 | - | let farmingAddress = Address(getBase58FromOracle(kFarmingAddress)) | |
60 | + | let cpmmContract = Address(getBase58FromOracle(kCpmmContract)) | |
109 | 61 | ||
110 | 62 | let USDN = getBase58FromOracle(kUSDNAssetId) | |
111 | 63 | ||
112 | 64 | let EURN = getBase58FromOracle(kEURNAssetId) | |
113 | 65 | ||
114 | 66 | let stakingAssets = getStringValue(oracle, kStakingAssets) | |
115 | 67 | ||
116 | - | let | |
68 | + | let activeGlob = valueOrElse(getBoolean(oracle, kActiveGlob), true) | |
117 | 69 | ||
118 | - | let | |
70 | + | let active = valueOrElse(getBoolean(this, kActive), true) | |
119 | 71 | ||
120 | - | let basePeriod = valueOrErrorMessage(getInteger(votingAddress, kBasePeriod), "Empty kBasePeriod") | |
121 | - | ||
122 | - | let startHeight = valueOrErrorMessage(getInteger(votingAddress, kStartHeight), "Empty kStartHeight") | |
123 | - | ||
124 | - | let periodLength = valueOrErrorMessage(getInteger(votingAddress, kPeriodLength), "Empty kPeriodLength") | |
125 | - | ||
126 | - | let firstHarvestEndPeriod = ((basePeriod + ((height - startHeight) / periodLength)) + 3) | |
127 | - | ||
128 | - | let active = if (getBooleanValue(oracle, kOracleActive)) | |
129 | - | then getBooleanValue(oracle, kOracleActiveExchangers) | |
130 | - | else false | |
131 | - | ||
132 | - | let feeScale6 = 1000000 | |
133 | - | ||
134 | - | let scale8 = 100000000 | |
135 | - | ||
136 | - | func accountBalance (assetId,pool) = match assetId { | |
137 | - | case id: ByteVector => | |
138 | - | assetBalance(pool, id) | |
139 | - | case waves: Unit => | |
140 | - | wavesBalance(pool).available | |
141 | - | case _ => | |
142 | - | throw("Match error") | |
143 | - | } | |
72 | + | func isActive () = if (if (active) | |
73 | + | then activeGlob | |
74 | + | else false) | |
75 | + | then unit | |
76 | + | else throw("DApp is inactive at this moment") | |
144 | 77 | ||
145 | 78 | ||
146 | - | func stakedAmount (assetId,pool) = { | |
147 | - | let stakedAmountCalculated = match assetId { | |
148 | - | case aId: ByteVector => | |
149 | - | if ((aId == USDN)) | |
150 | - | then getInteger(stakingUSDNAddress, ((("rpd_balance_" + toBase58String(aId)) + "_") + toString(pool))) | |
151 | - | else if ((aId == EURN)) | |
152 | - | then getInteger(stakingEURNAddress, ((("%s%s%s__stakingBalance__" + toBase58String(aId)) + "__") + toString(pool))) | |
153 | - | else 0 | |
154 | - | case _: Unit => | |
155 | - | valueOrElse(getInteger(pool, kLeasingAmount), 0) | |
156 | - | case _ => | |
157 | - | throw("Match error") | |
158 | - | } | |
159 | - | match stakedAmountCalculated { | |
160 | - | case i: Int => | |
161 | - | i | |
162 | - | case _ => | |
163 | - | 0 | |
164 | - | } | |
165 | - | } | |
79 | + | func isGlobalCaller (caller) = if ((caller == cpmmContract)) | |
80 | + | then unit | |
81 | + | else throw("Only global Contract can invoke this function") | |
166 | 82 | ||
167 | 83 | ||
168 | - | func getAssetInfo (assetId) = match assetId { | |
169 | - | case id: String|ByteVector => | |
170 | - | let $t040054177 = match id { | |
171 | - | case aId: ByteVector => | |
172 | - | $Tuple2(toBase58String(aId), aId) | |
173 | - | case aId: String => | |
174 | - | $Tuple2(aId, fromBase58String(aId)) | |
175 | - | case _ => | |
176 | - | throw("Match error") | |
177 | - | } | |
178 | - | let stringId = $t040054177._1 | |
179 | - | let bytesId = $t040054177._2 | |
180 | - | let info = valueOrErrorMessage(assetInfo(bytesId), (("Asset " + stringId) + " doesn't exist")) | |
181 | - | $Tuple3(stringId, info.name, info.decimals) | |
182 | - | case waves: Unit => | |
183 | - | $Tuple3("WAVES", "WAVES", 8) | |
184 | - | case _ => | |
185 | - | throw("Match error") | |
186 | - | } | |
84 | + | func isAdminCall (callerPubKey) = if (containsElement([adminPubKey1, adminPubKey2, adminPubKey3], callerPubKey)) | |
85 | + | then unit | |
86 | + | else throw("Only admin can call this function") | |
187 | 87 | ||
188 | 88 | ||
189 | 89 | func suspend (cause) = [BooleanEntry(kActive, false), StringEntry(kCause, cause)] | |
190 | 90 | ||
191 | 91 | ||
192 | - | func calculateFeeDiscount (userAddr) = { | |
193 | - | let swopAmount = valueOrElse(getInteger(govAddress, (toString(userAddr) + kUserSwopInGov)), 0) | |
194 | - | let gSwopAmount = valueOrElse(getInteger(govAddress, (toString(userAddr) + kUserGSwopInGov)), swopAmount) | |
195 | - | let discountValues = split(getStringValue(oracle, kDiscountValues), ",") | |
196 | - | let discounts = split(getStringValue(oracle, kDiscounts), ",") | |
197 | - | if (if ((gSwopAmount >= parseIntValue(discountValues[0]))) | |
198 | - | then (parseIntValue(discountValues[1]) > gSwopAmount) | |
199 | - | else false) | |
200 | - | then (feeScale6 - parseIntValue(discounts[0])) | |
201 | - | else if (if ((gSwopAmount >= parseIntValue(discountValues[1]))) | |
202 | - | then (parseIntValue(discountValues[2]) > gSwopAmount) | |
203 | - | else false) | |
204 | - | then (feeScale6 - parseIntValue(discounts[1])) | |
205 | - | else if (if ((gSwopAmount >= parseIntValue(discountValues[2]))) | |
206 | - | then (parseIntValue(discountValues[3]) > gSwopAmount) | |
207 | - | else false) | |
208 | - | then (feeScale6 - parseIntValue(discounts[2])) | |
209 | - | else if (if ((gSwopAmount >= parseIntValue(discountValues[3]))) | |
210 | - | then (parseIntValue(discountValues[4]) > gSwopAmount) | |
211 | - | else false) | |
212 | - | then (feeScale6 - parseIntValue(discounts[3])) | |
213 | - | else if ((gSwopAmount >= parseIntValue(discountValues[4]))) | |
214 | - | then (feeScale6 - parseIntValue(discounts[4])) | |
215 | - | else feeScale6 | |
92 | + | func calcStakingFuncAndAddres (stake,assetId) = if (stake) | |
93 | + | then if ((assetId == USDN)) | |
94 | + | then $Tuple2("lockNeutrino", stakingUSDNAddress) | |
95 | + | else $Tuple2("startStaking", stakingEURNAddress) | |
96 | + | else if ((assetId == USDN)) | |
97 | + | then $Tuple2("unlockNeutrino", stakingUSDNAddress) | |
98 | + | else $Tuple2("stopStaking", stakingEURNAddress) | |
99 | + | ||
100 | + | ||
101 | + | func calcStakingParams (stake,amount,assetId) = if (stake) | |
102 | + | then { | |
103 | + | let $t025932659 = calcStakingFuncAndAddres(stake, assetId) | |
104 | + | let call = $t025932659._1 | |
105 | + | let stakingAddr = $t025932659._2 | |
106 | + | $Tuple4(call, stakingAddr, nil, [AttachedPayment(assetId, amount)]) | |
107 | + | } | |
108 | + | else { | |
109 | + | let $t027452811 = calcStakingFuncAndAddres(stake, assetId) | |
110 | + | let call = $t027452811._1 | |
111 | + | let stakingAddr = $t027452811._2 | |
112 | + | $Tuple4(call, stakingAddr, [amount, toBase58String(assetId)], nil) | |
113 | + | } | |
114 | + | ||
115 | + | ||
116 | + | func collectPayments (acc,payment) = { | |
117 | + | let $t029733016 = acc | |
118 | + | let paymentAmounts = $t029733016._1 | |
119 | + | let paymentAssetIds = $t029733016._2 | |
120 | + | $Tuple2((paymentAmounts :+ payment.amount), (paymentAssetIds :+ (if ((payment.assetId == unit)) | |
121 | + | then base58'' | |
122 | + | else payment.assetId))) | |
216 | 123 | } | |
217 | 124 | ||
218 | 125 | ||
219 | - | func calculateFees (pmtAmount,minAmountToReceive,tokenFrom,tokenTo,fee,feeGovernance) = { | |
220 | - | let amountWithoutFee = fraction(tokenTo, pmtAmount, (pmtAmount + tokenFrom)) | |
221 | - | let amountWithFee = fraction(amountWithoutFee, (feeScale6 - fee), feeScale6) | |
222 | - | let governanceReward = fraction(amountWithoutFee, feeGovernance, feeScale6) | |
223 | - | if ((minAmountToReceive > amountWithFee)) | |
224 | - | then throw(((("Calculated amount to receive " + toString(amountWithFee)) + " is less than specified minimum ") + toString(minAmountToReceive))) | |
225 | - | else $Tuple3(amountWithoutFee, amountWithFee, governanceReward) | |
226 | - | } | |
126 | + | func collectState (result,source) = match source { | |
127 | + | case e: Issue|Burn|Reissue|ScriptTransfer|BinaryEntry|BooleanEntry|StringEntry|IntegerEntry => | |
128 | + | (result :+ e) | |
129 | + | case _ => | |
130 | + | result | |
131 | + | } | |
227 | 132 | ||
228 | 133 | ||
229 | - | func calculateVirtPay (pmtAmount,balance,fee) = { | |
230 | - | let F = (feeScale6 - fee) | |
231 | - | let k = fraction(fee, 60, 100) | |
232 | - | let a = (scale8 + fraction((F * k), scale8, (feeScale6 * feeScale6))) | |
233 | - | let b = ((((balance + fraction(balance, F, feeScale6)) + fraction(pmtAmount, F, feeScale6)) - pmtAmount) - fraction(pmtAmount, (F * k), (feeScale6 * feeScale6))) | |
234 | - | let c = (-(toBigInt(balance)) * toBigInt(pmtAmount)) | |
235 | - | let D = ((toBigInt(b) * toBigInt(b)) - fraction((toBigInt(4) * c), toBigInt(a), toBigInt(scale8))) | |
236 | - | toInt(fraction((-(toBigInt(b)) + sqrtBigInt(D, 0, 0, DOWN)), toBigInt(scale8), toBigInt((2 * a)))) | |
237 | - | } | |
134 | + | func collectData (result,source) = match source { | |
135 | + | case v: String => | |
136 | + | (result :+ v) | |
137 | + | case v: Int => | |
138 | + | (result :+ v) | |
139 | + | case v: Boolean => | |
140 | + | (result :+ v) | |
141 | + | case v: ByteVector => | |
142 | + | (result :+ v) | |
143 | + | case v: Unit => | |
144 | + | (result :+ v) | |
145 | + | case _ => | |
146 | + | throw() | |
147 | + | } | |
238 | 148 | ||
239 | 149 | ||
240 | - | func parsePaymentAsset (assetId) = if ((assetId == base58'')) | |
241 | - | then unit | |
242 | - | else assetId | |
150 | + | func callCommon (funcName,caller,args,payments) = valueOrElse(isActive(), { | |
151 | + | let $t039364020 = { | |
152 | + | let $l = payments | |
153 | + | let $s = size($l) | |
154 | + | let $acc0 = $Tuple2(nil, nil) | |
155 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
156 | + | then $a | |
157 | + | else collectPayments($a, $l[$i]) | |
243 | 158 | ||
159 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
160 | + | then $a | |
161 | + | else throw("List size exceeds 10") | |
244 | 162 | ||
245 | - | func suspendSuspicious (accountBalanceA,accountBalanceB,balanceA,balanceB,assetIdA,assetIdB) = suspend(((((((((((((((("Suspicious state. Actual balances: " + toString(accountBalanceA)) + " ") + assetIdA) + ", ") + toString(accountBalanceB)) + " ") + assetIdB) + ". State: ") + toString(balanceA)) + " ") + assetIdA) + ", ") + toString(balanceB)) + " ") + assetIdB)) | |
163 | + | $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) | |
164 | + | } | |
165 | + | let paymentAmounts = $t039364020._1 | |
166 | + | let paymentAssetIds = $t039364020._2 | |
167 | + | let lockPayment = if (if ((funcName == "replenishWithTwoTokens")) | |
168 | + | then (size(payments) == 3) | |
169 | + | else false) | |
170 | + | then [payments[2]] | |
171 | + | else if (if ((funcName == "replenishWithOneToken")) | |
172 | + | then (size(payments) == 2) | |
173 | + | else false) | |
174 | + | then [payments[1]] | |
175 | + | else nil | |
176 | + | let $t042494406 = { | |
177 | + | let @ = reentrantInvoke(cpmmContract, funcName, [caller, args, paymentAmounts, paymentAssetIds], lockPayment) | |
178 | + | if ($isInstanceOf(@, "(List[Any], List[Any])")) | |
179 | + | then @ | |
180 | + | else throw(($getType(@) + " couldn't be cast to (List[Any], List[Any])")) | |
181 | + | } | |
182 | + | if (($t042494406 == $t042494406)) | |
183 | + | then { | |
184 | + | let data = $t042494406._2 | |
185 | + | let actions = $t042494406._1 | |
186 | + | let mappedData = { | |
187 | + | let $l = data | |
188 | + | let $s = size($l) | |
189 | + | let $acc0 = nil | |
190 | + | func $f1_1 ($a,$i) = if (($i >= $s)) | |
191 | + | then $a | |
192 | + | else collectData($a, $l[$i]) | |
246 | 193 | ||
194 | + | func $f1_2 ($a,$i) = if (($i >= $s)) | |
195 | + | then $a | |
196 | + | else throw("List size exceeds 10") | |
247 | 197 | ||
248 | - | func isActive () = if (active) | |
249 | - | then unit | |
250 | - | else throw("DApp is inactive at this moment") | |
198 | + | $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) | |
199 | + | } | |
200 | + | let mappedActions = { | |
201 | + | let $l = actions | |
202 | + | let $s = size($l) | |
203 | + | let $acc0 = nil | |
204 | + | func $f2_1 ($a,$i) = if (($i >= $s)) | |
205 | + | then $a | |
206 | + | else collectState($a, $l[$i]) | |
251 | 207 | ||
208 | + | func $f2_2 ($a,$i) = if (($i >= $s)) | |
209 | + | then $a | |
210 | + | else throw("List size exceeds 15") | |
252 | 211 | ||
253 | - | func isOraclePool (poolAddress) = if (isDefined(getString(oracle, (kOraclePool + poolAddress)))) | |
254 | - | then unit | |
255 | - | else throw("DApp is not registered pool") | |
256 | - | ||
257 | - | ||
258 | - | func getPoolBalances (pool,assetIdA,assetIdB) = { | |
259 | - | let balanceA = getIntegerValue(pool, kBalanceA) | |
260 | - | let balanceB = getIntegerValue(pool, kBalanceB) | |
261 | - | let stakedAmountA = stakedAmount(assetIdA, pool) | |
262 | - | let stakedAmountB = stakedAmount(assetIdB, pool) | |
263 | - | let accountBalanceA = (accountBalance(assetIdA, pool) + stakedAmountA) | |
264 | - | let accountBalanceB = (accountBalance(assetIdB, pool) + stakedAmountB) | |
265 | - | let shareSupply = getIntegerValue(pool, kShareAssetSupply) | |
266 | - | $Tuple5(balanceA, balanceB, accountBalanceA, accountBalanceB, shareSupply) | |
267 | - | } | |
268 | - | ||
269 | - | ||
270 | - | func getPoolAssets (pool) = { | |
271 | - | let strAssetIdA = getStringValue(pool, kAssetIdA) | |
272 | - | let strAssetIdB = getStringValue(pool, kAssetIdB) | |
273 | - | let assetIdA = if ((strAssetIdA == "WAVES")) | |
274 | - | then unit | |
275 | - | else fromBase58String(strAssetIdA) | |
276 | - | let assetIdB = if ((strAssetIdB == "WAVES")) | |
277 | - | then unit | |
278 | - | else fromBase58String(strAssetIdB) | |
279 | - | let shareAssetId = fromBase58String(getStringValue(pool, kShareAssetId)) | |
280 | - | $Tuple5(strAssetIdA, strAssetIdB, assetIdA, assetIdB, shareAssetId) | |
281 | - | } | |
282 | - | ||
283 | - | ||
284 | - | func getFeeParams (pool,caller) = { | |
285 | - | let feeDiscount = calculateFeeDiscount(caller) | |
286 | - | let fee = fraction(getIntegerValue(pool, kFee), feeDiscount, feeScale6, CEILING) | |
287 | - | let govFee = fraction(fraction(fee, 40, 100), feeDiscount, feeScale6, CEILING) | |
288 | - | $Tuple2(fee, govFee) | |
289 | - | } | |
212 | + | $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) | |
213 | + | } | |
214 | + | $Tuple2(mappedActions, mappedData) | |
215 | + | } | |
216 | + | else throw("Strict value is not equal to itself.") | |
217 | + | }) | |
290 | 218 | ||
291 | 219 | ||
292 | 220 | @Callable(i) | |
293 | - | func init (callerBytes,args,pAmounts,pAssetIds) = { | |
294 | - | let caller = Address(callerBytes) | |
295 | - | let $t091849262 = $Tuple2(pAmounts[0], parsePaymentAsset(pAssetIds[0])) | |
296 | - | let pmtAmountA = $t091849262._1 | |
297 | - | let pmtAssetIdA = $t091849262._2 | |
298 | - | let $t092679345 = $Tuple2(pAmounts[1], parsePaymentAsset(pAssetIds[1])) | |
299 | - | let pmtAmountB = $t092679345._1 | |
300 | - | let pmtAssetIdB = $t092679345._2 | |
301 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.originCallerPublicKey))) | |
302 | - | then throw("Only admin can call this function") | |
303 | - | else if ((size(args) != 1)) | |
304 | - | then throw("Wrong args size") | |
305 | - | else if (isDefined(getBoolean(caller, kActive))) | |
306 | - | then throw("DApp is already active") | |
307 | - | else if ((pmtAssetIdA == pmtAssetIdB)) | |
308 | - | then throw("Assets must be different") | |
309 | - | else { | |
310 | - | let $t097809857 = getAssetInfo(pmtAssetIdA) | |
311 | - | let pmtStrAssetIdA = $t097809857._1 | |
312 | - | let pmtAssetNameA = $t097809857._2 | |
313 | - | let pmtDecimalsA = $t097809857._3 | |
314 | - | let $t098669943 = getAssetInfo(pmtAssetIdB) | |
315 | - | let pmtStrAssetIdB = $t098669943._1 | |
316 | - | let pmtAssetNameB = $t098669943._2 | |
317 | - | let pmtDecimalsB = $t098669943._3 | |
318 | - | let firstHarvest = (args[0] == "true") | |
319 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
320 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
321 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
322 | - | let arg1 = pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN) | |
323 | - | let arg2 = pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN) | |
324 | - | let arg3 = pow(10, 0, shareDecimals, 0, 0, DOWN) | |
325 | - | let shareInitialSupply = fraction(arg1, arg2, arg3) | |
326 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
327 | - | let shareIssueId = calculateAssetId(shareIssue) | |
328 | - | let stake1 = if (contains(stakingAssets, pmtStrAssetIdA)) | |
329 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
330 | - | else 0 | |
331 | - | if ((stake1 == stake1)) | |
332 | - | then { | |
333 | - | let stake2 = if (contains(stakingAssets, pmtStrAssetIdB)) | |
334 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
335 | - | else 0 | |
336 | - | if ((stake2 == stake2)) | |
337 | - | then { | |
338 | - | 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(caller, shareInitialSupply, shareIssueId)] | |
339 | - | if (firstHarvest) | |
340 | - | then $Tuple2(nil, $Tuple2((baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]), nil)) | |
341 | - | else $Tuple2(nil, $Tuple2(baseEntry, nil)) | |
342 | - | } | |
343 | - | else throw("Strict value is not equal to itself.") | |
344 | - | } | |
345 | - | else throw("Strict value is not equal to itself.") | |
346 | - | } | |
347 | - | } | |
221 | + | func callFunction (funcName,args) = callCommon(funcName, i.caller.bytes, args, i.payments) | |
348 | 222 | ||
349 | 223 | ||
350 | 224 | ||
351 | 225 | @Callable(i) | |
352 | - | func initWithInitRatio (callerBytes,args,pAmounts,pAssetIds) = { | |
353 | - | let caller = Address(callerBytes) | |
354 | - | let $t01216412364 = $Tuple5(parseIntValue(args[0]), parseIntValue(args[1]), args[2], args[3], (args[4] == "true")) | |
355 | - | let amtAssetA = $t01216412364._1 | |
356 | - | let amtAssetB = $t01216412364._2 | |
357 | - | let assetIdAStr = $t01216412364._3 | |
358 | - | let assetIdBStr = $t01216412364._4 | |
359 | - | let firstHarvest = $t01216412364._5 | |
360 | - | if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.originCallerPublicKey))) | |
361 | - | then throw("Only admin can call this function") | |
362 | - | else if ((size(args) != 5)) | |
363 | - | then throw("Wrong args size") | |
364 | - | else if (isDefined(getBoolean(caller, kActive))) | |
365 | - | then throw("DApp is already active") | |
366 | - | else if ((assetIdAStr == assetIdBStr)) | |
367 | - | then throw("Assets must be different") | |
368 | - | else { | |
369 | - | let $t01279912876 = getAssetInfo(assetIdAStr) | |
370 | - | let pmtStrAssetIdA = $t01279912876._1 | |
371 | - | let pmtAssetNameA = $t01279912876._2 | |
372 | - | let pmtDecimalsA = $t01279912876._3 | |
373 | - | let $t01288512962 = getAssetInfo(assetIdBStr) | |
374 | - | let pmtStrAssetIdB = $t01288512962._1 | |
375 | - | let pmtAssetNameB = $t01288512962._2 | |
376 | - | let pmtDecimalsB = $t01288512962._3 | |
377 | - | let shareName = ((("s" + take(pmtAssetNameA, 7)) + "_") + take(pmtAssetNameB, 7)) | |
378 | - | let shareDescription = ((((("ShareToken of SwopFi protocol for " + pmtAssetNameA) + " and ") + pmtAssetNameB) + " at address ") + toString(this)) | |
379 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
380 | - | let shareInitialSupply = 0 | |
381 | - | let shareIssue = Issue(shareName, shareDescription, shareInitialSupply, shareDecimals, true) | |
382 | - | let shareIssueId = calculateAssetId(shareIssue) | |
383 | - | 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)] | |
384 | - | if (firstHarvest) | |
385 | - | then $Tuple2(nil, $Tuple2((baseEntry ++ [BooleanEntry(kFirstHarvest, firstHarvest), IntegerEntry(kFirstHarvestHeight, (startHeight + (firstHarvestEndPeriod * periodLength)))]), nil)) | |
386 | - | else $Tuple2(nil, $Tuple2(baseEntry, nil)) | |
387 | - | } | |
388 | - | } | |
226 | + | func shutdown () = valueOrElse(isAdminCall(i.callerPublicKey), if (!(active)) | |
227 | + | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, kCause), "the cause wasn't specified"))) | |
228 | + | else suspend("Paused by admin")) | |
389 | 229 | ||
390 | 230 | ||
391 | 231 | ||
392 | 232 | @Callable(i) | |
393 | - | func keepLimitForFirstHarvest (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminInvokePubKey], i.originCallerPublicKey))) | |
394 | - | then throw("Only admin can call this function") | |
395 | - | else if ((size(args) != 1)) | |
396 | - | then throw("Wrong args size") | |
397 | - | else { | |
398 | - | let shareLimit = parseIntValue(args[0]) | |
399 | - | $Tuple2(nil, $Tuple2([IntegerEntry(kShareLimit, shareLimit)], nil)) | |
400 | - | })) | |
233 | + | func activate () = valueOrElse(isAdminCall(i.callerPublicKey), if (active) | |
234 | + | then throw("DApp is already active") | |
235 | + | else [BooleanEntry(kActive, true), DeleteEntry(kCause)]) | |
401 | 236 | ||
402 | 237 | ||
403 | 238 | ||
404 | 239 | @Callable(i) | |
405 | - | func exchange (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
406 | - | let caller = Address(callerBytes) | |
407 | - | let $t01534815424 = $Tuple2(pAmounts[0], parsePaymentAsset(pAssetIds[0])) | |
408 | - | let pmtAmount = $t01534815424._1 | |
409 | - | let pmtAssetId = $t01534815424._2 | |
410 | - | let minAmountToReceive = parseIntValue(args[0]) | |
411 | - | let $t01549715573 = getPoolAssets(i.caller) | |
412 | - | let strAssetIdA = $t01549715573._1 | |
413 | - | let strAssetIdB = $t01549715573._2 | |
414 | - | let assetIdA = $t01549715573._3 | |
415 | - | let assetIdB = $t01549715573._4 | |
416 | - | let $t01558615692 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
417 | - | let balanceA = $t01558615692._1 | |
418 | - | let balanceB = $t01558615692._2 | |
419 | - | let accountBalanceA = $t01558615692._3 | |
420 | - | let accountBalanceB = $t01558615692._4 | |
421 | - | if ((size(args) != 1)) | |
422 | - | then throw("Wrong args size") | |
423 | - | else if (if ((balanceA == 0)) | |
424 | - | then true | |
425 | - | else (balanceB == 0)) | |
426 | - | then throw("Can't exchange with zero balance") | |
427 | - | else if ((0 >= minAmountToReceive)) | |
428 | - | then throw(("Minimal amount to receive must be positive. Actual: " + toString(minAmountToReceive))) | |
429 | - | else if ((size(pAmounts) != 1)) | |
430 | - | then throw("One attached payment expected") | |
431 | - | else if (!(containsElement([assetIdA, assetIdB], pmtAssetId))) | |
432 | - | then throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
433 | - | else if (if ((balanceA > accountBalanceA)) | |
434 | - | then true | |
435 | - | else (balanceB > accountBalanceB)) | |
436 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))) | |
437 | - | else { | |
438 | - | let $t01666016718 = getFeeParams(i.caller, i.originCaller) | |
439 | - | let fee = $t01666016718._1 | |
440 | - | let govFee = $t01666016718._2 | |
441 | - | let $t01673517072 = if ((pmtAssetId == assetIdA)) | |
442 | - | then calculateFees(pmtAmount, minAmountToReceive, balanceA, balanceB, fee, govFee) | |
443 | - | else calculateFees(pmtAmount, minAmountToReceive, balanceB, balanceA, fee, govFee) | |
444 | - | let amountWithoutFee = $t01673517072._1 | |
445 | - | let amountWithFee = $t01673517072._2 | |
446 | - | let governanceReward = $t01673517072._3 | |
447 | - | let $t01709017415 = if ((pmtAssetId == assetIdA)) | |
448 | - | then $Tuple3((balanceA + pmtAmount), ((balanceB - amountWithFee) - governanceReward), assetIdB) | |
449 | - | else $Tuple3(((balanceA - amountWithFee) - governanceReward), (balanceB + pmtAmount), assetIdA) | |
450 | - | let newBalanceA = $t01709017415._1 | |
451 | - | let newBalanceB = $t01709017415._2 | |
452 | - | let assetIdSend = $t01709017415._3 | |
453 | - | let $t01743317683 = if ((pmtAssetId == assetIdA)) | |
454 | - | then $Tuple2(pmtAmount, (amountWithFee + governanceReward)) | |
455 | - | else $Tuple2((amountWithFee + governanceReward), pmtAmount) | |
456 | - | let stakeAmountA = $t01743317683._1 | |
457 | - | let stakeAmountB = $t01743317683._2 | |
458 | - | let stake1 = if (contains(stakingAssets, strAssetIdA)) | |
459 | - | then invoke(i.caller, "stakeUnstake", [(pmtAssetId == assetIdA), stakeAmountA, strAssetIdA], nil) | |
460 | - | else 0 | |
461 | - | if ((stake1 == stake1)) | |
462 | - | then { | |
463 | - | let stake2 = if (contains(stakingAssets, strAssetIdB)) | |
464 | - | then invoke(i.caller, "stakeUnstake", [(pmtAssetId == assetIdB), stakeAmountB, strAssetIdB], nil) | |
465 | - | else 0 | |
466 | - | if ((stake2 == stake2)) | |
467 | - | then $Tuple2(nil, $Tuple2([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), ScriptTransfer(caller, amountWithFee, assetIdSend), ScriptTransfer(moneyBoxAddress, governanceReward, assetIdSend)], [amountWithFee, assetIdSend])) | |
468 | - | else throw("Strict value is not equal to itself.") | |
469 | - | } | |
470 | - | else throw("Strict value is not equal to itself.") | |
471 | - | } | |
240 | + | func stakeUnstake (stake,amount,assetIdString) = valueOrElse(isActive(), if ((i.caller != cpmmContract)) | |
241 | + | then throw("Only global Contract can invoke this function") | |
242 | + | else if ((assetIdString == "WAVES")) | |
243 | + | then { | |
244 | + | let pool = addressFromStringValue(valueOrErrorMessage(getString(oracle, kLeasingPool), "No leasing pool in oracle")) | |
245 | + | let leasingId = getBinary(this, kLeasingId) | |
246 | + | let leasingAmount = valueOrElse(getInteger(this, kLeasingAmount), 0) | |
247 | + | let newLeaseAmount = if (stake) | |
248 | + | then (leasingAmount + amount) | |
249 | + | else (leasingAmount - amount) | |
250 | + | let newLease = Lease(pool, newLeaseAmount) | |
251 | + | let newLeaseId = calculateLeaseId(newLease) | |
252 | + | let baseEtry = [newLease, BinaryEntry(kLeasingId, newLeaseId), IntegerEntry(kLeasingAmount, newLeaseAmount)] | |
253 | + | match leasingId { | |
254 | + | case lId: ByteVector => | |
255 | + | ([LeaseCancel(lId)] ++ baseEtry) | |
256 | + | case _ => | |
257 | + | baseEtry | |
258 | + | } | |
259 | + | } | |
260 | + | else { | |
261 | + | let $t064026505 = calcStakingParams(stake, amount, fromBase58String(assetIdString)) | |
262 | + | let call = $t064026505._1 | |
263 | + | let addr = $t064026505._2 | |
264 | + | let params = $t064026505._3 | |
265 | + | let payments = $t064026505._4 | |
266 | + | let inv = invoke(addr, call, params, payments) | |
267 | + | if ((inv == inv)) | |
268 | + | then nil | |
269 | + | else throw("Strict value is not equal to itself.") | |
270 | + | }) | |
271 | + | ||
272 | + | ||
273 | + | ||
274 | + | @Callable(i) | |
275 | + | func reissueShareToken (amount) = valueOrElse(isGlobalCaller(i.caller), valueOrElse(isActive(), { | |
276 | + | let shareAssetId = fromBase58String(getStringValue(this, kShareAssetId)) | |
277 | + | [Reissue(shareAssetId, amount, true), ScriptTransfer(i.caller, amount, shareAssetId)] | |
472 | 278 | })) | |
473 | 279 | ||
474 | 280 | ||
475 | 281 | ||
476 | 282 | @Callable(i) | |
477 | - | func replenishWithTwoTokens (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
478 | - | let caller = Address(callerBytes) | |
479 | - | let pmtAssetIdA = parsePaymentAsset(pAssetIds[0]) | |
480 | - | let pmtAssetIdB = parsePaymentAsset(pAssetIds[1]) | |
481 | - | let stakeFarming = (args[0] == "true") | |
482 | - | let lockType = parseIntValue(args[1]) | |
483 | - | let $t01894619036 = getPoolAssets(i.caller) | |
484 | - | let strAssetIdA = $t01894619036._1 | |
485 | - | let strAssetIdB = $t01894619036._2 | |
486 | - | let assetIdA = $t01894619036._3 | |
487 | - | let assetIdB = $t01894619036._4 | |
488 | - | let shareAssetId = $t01894619036._5 | |
489 | - | let $t01904919173 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
490 | - | let balanceA = $t01904919173._1 | |
491 | - | let balanceB = $t01904919173._2 | |
492 | - | let accountBalanceA = $t01904919173._3 | |
493 | - | let accountBalanceB = $t01904919173._4 | |
494 | - | let shareAssetSupply = $t01904919173._5 | |
495 | - | if ((size(args) != 2)) | |
496 | - | then throw("Wrong args size") | |
497 | - | else if (if ((size(pAmounts) != 2)) | |
498 | - | then (size(pAmounts) != 3) | |
499 | - | else false) | |
500 | - | then throw("Two or three payments expected") | |
501 | - | else if (if ((pmtAssetIdA != assetIdA)) | |
502 | - | then true | |
503 | - | else (pmtAssetIdB != assetIdB)) | |
504 | - | then throw(((("Incorrect assets attached. Expected: " + strAssetIdA) + " and ") + strAssetIdB)) | |
505 | - | else if (if ((balanceA > accountBalanceA)) | |
506 | - | then true | |
507 | - | else (balanceB > accountBalanceB)) | |
508 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pAmounts[0], pmtAssetIdA), ScriptTransfer(caller, pAmounts[1], pmtAssetIdB)] ++ (if ((size(pAmounts) == 3)) | |
509 | - | then [AttachedPayment(if ((pAssetIds[2] == base58'')) | |
510 | - | then unit | |
511 | - | else pAssetIds[2], pAmounts[2])] | |
512 | - | else (nil ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))))) | |
513 | - | else { | |
514 | - | let $t02017420251 = getAssetInfo(pmtAssetIdA) | |
515 | - | let pmtStrAssetIdA = $t02017420251._1 | |
516 | - | let pmtAssetNameA = $t02017420251._2 | |
517 | - | let pmtDecimalsA = $t02017420251._3 | |
518 | - | let $t02026820345 = getAssetInfo(pmtAssetIdB) | |
519 | - | let pmtStrAssetIdB = $t02026820345._1 | |
520 | - | let pmtAssetNameB = $t02026820345._2 | |
521 | - | let pmtDecimalsB = $t02026820345._3 | |
522 | - | let initial = ((balanceA + balanceB) == 0) | |
523 | - | let $t02042021263 = if (initial) | |
524 | - | then $Tuple5(pAmounts[0], pAmounts[1], 0, pmtAssetIdA, 1) | |
525 | - | else { | |
526 | - | let ratioShareTokensInA = fraction(scale8, pAmounts[0], balanceA) | |
527 | - | let ratioShareTokensInB = fraction(scale8, pAmounts[1], balanceB) | |
528 | - | if ((ratioShareTokensInB > ratioShareTokensInA)) | |
529 | - | then { | |
530 | - | let pmt = fraction(pAmounts[0], balanceB, balanceA) | |
531 | - | $Tuple5(pAmounts[0], pmt, (pAmounts[1] - pmt), pmtAssetIdB, ratioShareTokensInA) | |
532 | - | } | |
533 | - | else { | |
534 | - | let pmt = fraction(pAmounts[1], balanceA, balanceB) | |
535 | - | $Tuple5(pmt, pAmounts[1], (pAmounts[0] - pmt), pmtAssetIdA, ratioShareTokensInB) | |
536 | - | } | |
537 | - | } | |
538 | - | let pmtAmountA = $t02042021263._1 | |
539 | - | let pmtAmountB = $t02042021263._2 | |
540 | - | let change = $t02042021263._3 | |
541 | - | let changeAssetId = $t02042021263._4 | |
542 | - | let shareTokenRatio = $t02042021263._5 | |
543 | - | let shareTokenToPayAmount = if (initial) | |
544 | - | then { | |
545 | - | let shareDecimals = ((pmtDecimalsA + pmtDecimalsB) / 2) | |
546 | - | fraction(pow(pmtAmountA, pmtDecimalsA, 5, 1, pmtDecimalsA, DOWN), pow(pmtAmountB, pmtDecimalsB, 5, 1, pmtDecimalsB, DOWN), pow(10, 0, shareDecimals, 0, 0, DOWN)) | |
547 | - | } | |
548 | - | else fraction(shareTokenRatio, shareAssetSupply, scale8) | |
549 | - | if ((shareTokenToPayAmount == 0)) | |
550 | - | then throw("Too small amount to replenish") | |
551 | - | else if ((0 > change)) | |
552 | - | then throw("Change < 0") | |
553 | - | else { | |
554 | - | let stake1 = if (contains(stakingAssets, pmtStrAssetIdA)) | |
555 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountA, pmtStrAssetIdA], nil) | |
556 | - | else 0 | |
557 | - | if ((stake1 == stake1)) | |
558 | - | then { | |
559 | - | let stake2 = if (contains(stakingAssets, pmtStrAssetIdB)) | |
560 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmountB, pmtStrAssetIdB], nil) | |
561 | - | else 0 | |
562 | - | if ((stake2 == stake2)) | |
563 | - | then { | |
564 | - | let shareTokenST = if (stakeFarming) | |
565 | - | then { | |
566 | - | let stPayments = ([AttachedPayment(shareAssetId, shareTokenToPayAmount)] ++ (if ((size(pAmounts) == 3)) | |
567 | - | then [AttachedPayment(if ((pAssetIds[2] == base58'')) | |
568 | - | then unit | |
569 | - | else pAssetIds[2], pAmounts[2])] | |
570 | - | else nil)) | |
571 | - | let reissue = invoke(i.caller, "reissueShareToken", [shareTokenToPayAmount], nil) | |
572 | - | if ((reissue == reissue)) | |
573 | - | then { | |
574 | - | let stake3 = invoke(farmingAddress, "lockShareTokensFromPool", [callerBytes, toString(i.caller), lockType], stPayments) | |
575 | - | if ((stake3 == stake3)) | |
576 | - | then nil | |
577 | - | else throw("Strict value is not equal to itself.") | |
578 | - | } | |
579 | - | else throw("Strict value is not equal to itself.") | |
580 | - | } | |
581 | - | else [Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(caller, shareTokenToPayAmount, shareAssetId)] | |
582 | - | $Tuple2(nil, $Tuple2(([IntegerEntry(kBalanceA, (balanceA + pmtAmountA)), IntegerEntry(kBalanceB, (balanceB + pmtAmountB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), ScriptTransfer(caller, change, changeAssetId)] ++ shareTokenST), nil)) | |
583 | - | } | |
584 | - | else throw("Strict value is not equal to itself.") | |
585 | - | } | |
586 | - | else throw("Strict value is not equal to itself.") | |
587 | - | } | |
588 | - | } | |
589 | - | })) | |
283 | + | func replenishWithTwoTokens (slippageTolerance) = callCommon("replenishWithTwoTokens", i.caller.bytes, ["false", "0"], i.payments) | |
590 | 284 | ||
591 | 285 | ||
592 | 286 | ||
593 | 287 | @Callable(i) | |
594 | - | func replenishWithOneToken (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
595 | - | let caller = Address(callerBytes) | |
596 | - | let pmtAssetId = parsePaymentAsset(pAssetIds[0]) | |
597 | - | let pmtAmount = pAmounts[0] | |
598 | - | let virtGetMinAmount = parseIntValue(args[0]) | |
599 | - | let stakeFarming = (args[1] == "true") | |
600 | - | let lockType = parseIntValue(args[2]) | |
601 | - | let $t02416824258 = getPoolAssets(i.caller) | |
602 | - | let strAssetIdA = $t02416824258._1 | |
603 | - | let strAssetIdB = $t02416824258._2 | |
604 | - | let assetIdA = $t02416824258._3 | |
605 | - | let assetIdB = $t02416824258._4 | |
606 | - | let shareAssetId = $t02416824258._5 | |
607 | - | let $t02427124395 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
608 | - | let balanceA = $t02427124395._1 | |
609 | - | let balanceB = $t02427124395._2 | |
610 | - | let accountBalanceA = $t02427124395._3 | |
611 | - | let accountBalanceB = $t02427124395._4 | |
612 | - | let shareAssetSupply = $t02427124395._5 | |
613 | - | let initial = ((balanceA + balanceB) == 0) | |
614 | - | if ((size(args) != 3)) | |
615 | - | then throw("Wrong args size") | |
616 | - | else if (if ((size(pAmounts) != 1)) | |
617 | - | then (size(pAmounts) != 2) | |
618 | - | else false) | |
619 | - | then throw("Two or one attached assets expected") | |
620 | - | else if (if ((pmtAssetId != assetIdA)) | |
621 | - | then (pmtAssetId != assetIdB) | |
622 | - | else false) | |
623 | - | then throw(((("Incorrect asset attached. Expected: " + strAssetIdA) + " or ") + strAssetIdB)) | |
624 | - | else if (initial) | |
625 | - | then throw("For initial exchanger you need to use two tokens") | |
626 | - | else if (if ((balanceA > accountBalanceA)) | |
627 | - | then true | |
628 | - | else (balanceB > accountBalanceB)) | |
629 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ (if ((size(pAmounts) == 2)) | |
630 | - | then [AttachedPayment(if ((pAssetIds[2] == base58'')) | |
631 | - | then unit | |
632 | - | else pAssetIds[2], pAmounts[2])] | |
633 | - | else (nil ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))))) | |
634 | - | else { | |
635 | - | let $t02545125509 = getFeeParams(i.caller, i.originCaller) | |
636 | - | let fee = $t02545125509._1 | |
637 | - | let govFee = $t02545125509._2 | |
638 | - | let $t02552627732 = if ((pmtAssetId == assetIdA)) | |
639 | - | then { | |
640 | - | let virtPayAmount = calculateVirtPay(pmtAmount, balanceA, fee) | |
641 | - | let $t02580525942 = calculateFees(virtPayAmount, virtGetMinAmount, balanceA, balanceB, fee, govFee) | |
642 | - | let amountWithoutFee = $t02580525942._1 | |
643 | - | let amountWithFee = $t02580525942._2 | |
644 | - | let governanceReward = $t02580525942._3 | |
645 | - | let balanceAVirt = (balanceA + virtPayAmount) | |
646 | - | let balanceBVirt = ((balanceB + amountWithoutFee) - governanceReward) | |
647 | - | let newBalanceA = (balanceA + pmtAmount) | |
648 | - | let newBalanceB = (balanceB - governanceReward) | |
649 | - | let ratioShareTokensInA = fraction((pmtAmount - virtPayAmount), scale8, balanceAVirt) | |
650 | - | let ratioShareTokensInB = fraction(amountWithFee, scale8, balanceBVirt) | |
651 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
652 | - | $Tuple7(newBalanceA, newBalanceB, shareTokenToPayAmount, governanceReward, assetIdB, strAssetIdB, strAssetIdA) | |
653 | - | } | |
654 | - | else { | |
655 | - | let virtPayAmount = calculateVirtPay(pmtAmount, balanceB, fee) | |
656 | - | let $t02683726974 = calculateFees(virtPayAmount, virtGetMinAmount, balanceB, balanceA, fee, govFee) | |
657 | - | let amountWithoutFee = $t02683726974._1 | |
658 | - | let amountWithFee = $t02683726974._2 | |
659 | - | let governanceReward = $t02683726974._3 | |
660 | - | let balanceAVirt = ((balanceA + amountWithoutFee) - governanceReward) | |
661 | - | let balanceBVirt = (balanceB + virtPayAmount) | |
662 | - | let newBalanceA = (balanceA - governanceReward) | |
663 | - | let newBalanceB = (balanceB + pmtAmount) | |
664 | - | let ratioShareTokensInA = fraction(amountWithFee, scale8, balanceAVirt) | |
665 | - | let ratioShareTokensInB = fraction((pmtAmount - virtPayAmount), scale8, balanceBVirt) | |
666 | - | let shareTokenToPayAmount = fraction(min([ratioShareTokensInA, ratioShareTokensInB]), shareAssetSupply, scale8) | |
667 | - | $Tuple7(newBalanceA, newBalanceB, shareTokenToPayAmount, governanceReward, assetIdA, strAssetIdA, strAssetIdB) | |
668 | - | } | |
669 | - | let newBalanceA = $t02552627732._1 | |
670 | - | let newBalanceB = $t02552627732._2 | |
671 | - | let shareTokenToPayAmount = $t02552627732._3 | |
672 | - | let govReward = $t02552627732._4 | |
673 | - | let govRewardAsset = $t02552627732._5 | |
674 | - | let govRewardAssetStr = $t02552627732._6 | |
675 | - | let pmtAssetIdStr = $t02552627732._7 | |
676 | - | if ((shareTokenToPayAmount == 0)) | |
677 | - | then throw("Too small amount to replenish") | |
678 | - | else { | |
679 | - | let stake1 = if (contains(stakingAssets, pmtAssetIdStr)) | |
680 | - | then invoke(i.caller, "stakeUnstake", [true, pmtAmount, pmtAssetIdStr], nil) | |
681 | - | else 0 | |
682 | - | if ((stake1 == stake1)) | |
683 | - | then { | |
684 | - | let stake2 = if (contains(stakingAssets, govRewardAssetStr)) | |
685 | - | then invoke(i.caller, "stakeUnstake", [false, govReward, govRewardAssetStr], nil) | |
686 | - | else 0 | |
687 | - | if ((stake2 == stake2)) | |
688 | - | then { | |
689 | - | let shareTokenST = if (stakeFarming) | |
690 | - | then { | |
691 | - | let stPayments = ([AttachedPayment(shareAssetId, shareTokenToPayAmount)] ++ (if ((size(pAmounts) == 2)) | |
692 | - | then [AttachedPayment(if ((pAssetIds[1] == base58'')) | |
693 | - | then unit | |
694 | - | else pAssetIds[1], pAmounts[1])] | |
695 | - | else nil)) | |
696 | - | let reissue = invoke(i.caller, "reissueShareToken", [shareTokenToPayAmount], nil) | |
697 | - | if ((reissue == reissue)) | |
698 | - | then { | |
699 | - | let stake3 = invoke(farmingAddress, "lockShareTokensFromPool", [callerBytes, toString(i.caller), lockType], stPayments) | |
700 | - | if ((stake3 == stake3)) | |
701 | - | then nil | |
702 | - | else throw("Strict value is not equal to itself.") | |
703 | - | } | |
704 | - | else throw("Strict value is not equal to itself.") | |
705 | - | } | |
706 | - | else [Reissue(shareAssetId, shareTokenToPayAmount, true), ScriptTransfer(caller, shareTokenToPayAmount, shareAssetId)] | |
707 | - | $Tuple2(nil, $Tuple2(([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), IntegerEntry(kShareAssetSupply, (shareAssetSupply + shareTokenToPayAmount)), ScriptTransfer(moneyBoxAddress, govReward, govRewardAsset)] ++ shareTokenST), nil)) | |
708 | - | } | |
709 | - | else throw("Strict value is not equal to itself.") | |
710 | - | } | |
711 | - | else throw("Strict value is not equal to itself.") | |
712 | - | } | |
713 | - | } | |
714 | - | })) | |
288 | + | func withdraw () = callCommon("withdraw", i.caller.bytes, ["0"], i.payments) | |
715 | 289 | ||
716 | 290 | ||
717 | 291 | ||
718 | 292 | @Callable(i) | |
719 | - | func withdraw (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
720 | - | let time = lastBlock.timestamp | |
721 | - | let caller = Address(callerBytes) | |
722 | - | let $t02988629976 = getPoolAssets(i.caller) | |
723 | - | let strAssetIdA = $t02988629976._1 | |
724 | - | let strAssetIdB = $t02988629976._2 | |
725 | - | let assetIdA = $t02988629976._3 | |
726 | - | let assetIdB = $t02988629976._4 | |
727 | - | let shareAssetId = $t02988629976._5 | |
728 | - | let $t02998930113 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
729 | - | let balanceA = $t02998930113._1 | |
730 | - | let balanceB = $t02998930113._2 | |
731 | - | let accountBalanceA = $t02998930113._3 | |
732 | - | let accountBalanceB = $t02998930113._4 | |
733 | - | let shareAssetSupply = $t02998930113._5 | |
734 | - | let $t03012630534 = if ((size(pAmounts) == 1)) | |
735 | - | then { | |
736 | - | let pAsset = parsePaymentAsset(pAssetIds[0]) | |
737 | - | if ((pAsset != shareAssetId)) | |
738 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
739 | - | else $Tuple2(pAmounts[0], pAsset) | |
740 | - | } | |
741 | - | else $Tuple2(0, shareAssetId) | |
742 | - | let pmtAmount = $t03012630534._1 | |
743 | - | let pmtAssetId = $t03012630534._2 | |
744 | - | if ((size(args) != 1)) | |
745 | - | then throw("Wrong args size") | |
746 | - | else if ((size(pAmounts) > 1)) | |
747 | - | then throw("One attached payment expected") | |
748 | - | else if (if ((balanceA > accountBalanceA)) | |
749 | - | then true | |
750 | - | else (balanceB > accountBalanceB)) | |
751 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))) | |
752 | - | else { | |
753 | - | let unlockAmount = parseIntValue(valueOrElse(args[0], "0")) | |
754 | - | let unlock = if ((unlockAmount > 0)) | |
755 | - | then invoke(farmingAddress, "withdrawShareTokensFromPool", [callerBytes, toString(i.caller), unlockAmount], nil) | |
756 | - | else 0 | |
757 | - | if ((unlock == unlock)) | |
758 | - | then { | |
759 | - | let withdrawAmount = (pmtAmount + unlockAmount) | |
760 | - | let amountToPayA = fraction(withdrawAmount, balanceA, shareAssetSupply) | |
761 | - | let amountToPayB = fraction(withdrawAmount, balanceB, shareAssetSupply) | |
762 | - | let stake1 = if (contains(stakingAssets, strAssetIdA)) | |
763 | - | then invoke(i.caller, "stakeUnstake", [false, amountToPayA, strAssetIdA], nil) | |
764 | - | else 0 | |
765 | - | if ((stake1 == stake1)) | |
766 | - | then { | |
767 | - | let stake2 = if (contains(stakingAssets, strAssetIdB)) | |
768 | - | then invoke(i.caller, "stakeUnstake", [false, amountToPayB, strAssetIdB], nil) | |
769 | - | else 0 | |
770 | - | if ((stake2 == stake2)) | |
771 | - | then $Tuple2([ScriptTransfer(i.caller, unlockAmount, shareAssetId)], $Tuple2([IntegerEntry(kBalanceA, (balanceA - amountToPayA)), IntegerEntry(kBalanceB, (balanceB - amountToPayB)), IntegerEntry(kShareAssetSupply, (shareAssetSupply - withdrawAmount)), Burn(shareAssetId, withdrawAmount), ScriptTransfer(caller, amountToPayA, assetIdA), ScriptTransfer(caller, amountToPayB, assetIdB)], nil)) | |
772 | - | else throw("Strict value is not equal to itself.") | |
773 | - | } | |
774 | - | else throw("Strict value is not equal to itself.") | |
775 | - | } | |
776 | - | else throw("Strict value is not equal to itself.") | |
777 | - | } | |
778 | - | })) | |
779 | - | ||
780 | - | ||
781 | - | ||
782 | - | @Callable(i) | |
783 | - | func withdrawOneToken (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
784 | - | let caller = Address(callerBytes) | |
785 | - | let withdrawAsset = if ((args[0] == "")) | |
786 | - | then unit | |
787 | - | else fromBase58String(args[0]) | |
788 | - | let $t03284532935 = getPoolAssets(i.caller) | |
789 | - | let strAssetIdA = $t03284532935._1 | |
790 | - | let strAssetIdB = $t03284532935._2 | |
791 | - | let assetIdA = $t03284532935._3 | |
792 | - | let assetIdB = $t03284532935._4 | |
793 | - | let shareAssetId = $t03284532935._5 | |
794 | - | let $t03294833072 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
795 | - | let balanceA = $t03294833072._1 | |
796 | - | let balanceB = $t03294833072._2 | |
797 | - | let accountBalanceA = $t03294833072._3 | |
798 | - | let accountBalanceB = $t03294833072._4 | |
799 | - | let shareAssetSupply = $t03294833072._5 | |
800 | - | let $t03308533465 = if ((size(pAmounts) == 1)) | |
801 | - | then { | |
802 | - | let pAsset = parsePaymentAsset(pAssetIds[0]) | |
803 | - | if ((pAsset != shareAssetId)) | |
804 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
805 | - | else $Tuple2(pAmounts[0], pAsset) | |
806 | - | } | |
807 | - | else $Tuple2(0, shareAssetId) | |
808 | - | let pmtAmount = $t03308533465._1 | |
809 | - | let pmtAssetId = $t03308533465._2 | |
810 | - | let virtMinToRecive = parseIntValue(args[1]) | |
811 | - | if ((size(args) != 3)) | |
812 | - | then throw("Wrong args size") | |
813 | - | else if ((size(pAmounts) > 1)) | |
814 | - | then throw("One attached payment expected") | |
815 | - | else if ((pmtAssetId != shareAssetId)) | |
816 | - | then throw(("Incorrect asset attached. Expected: " + toBase58String(shareAssetId))) | |
817 | - | else if (!(containsElement([assetIdA, assetIdB], withdrawAsset))) | |
818 | - | then throw("Incorrect withdraw asset.") | |
819 | - | else if (if ((balanceA > accountBalanceA)) | |
820 | - | then true | |
821 | - | else (balanceB > accountBalanceB)) | |
822 | - | then $Tuple2(nil, ([ScriptTransfer(caller, pmtAmount, pmtAssetId)] ++ suspendSuspicious(accountBalanceA, accountBalanceB, balanceA, balanceB, strAssetIdA, strAssetIdB))) | |
823 | - | else { | |
824 | - | let unlockAmount = parseIntValue(valueOrElse(args[2], "0")) | |
825 | - | let unlock = if ((unlockAmount > 0)) | |
826 | - | then invoke(farmingAddress, "withdrawShareTokensFromPool", [callerBytes, toString(i.caller), unlockAmount], nil) | |
827 | - | else 0 | |
828 | - | if ((unlock == unlock)) | |
829 | - | then { | |
830 | - | let withdrawAmount = (pmtAmount + unlockAmount) | |
831 | - | let amountToPayA = fraction(withdrawAmount, balanceA, shareAssetSupply) | |
832 | - | let amountToPayB = fraction(withdrawAmount, balanceB, shareAssetSupply) | |
833 | - | let $t03481334871 = getFeeParams(i.caller, i.originCaller) | |
834 | - | let fee = $t03481334871._1 | |
835 | - | let govFee = $t03481334871._2 | |
836 | - | let $t03488835288 = if ((withdrawAsset == assetIdA)) | |
837 | - | then calculateFees(amountToPayB, virtMinToRecive, (balanceB - amountToPayB), (balanceA - amountToPayA), fee, govFee) | |
838 | - | else calculateFees(amountToPayA, virtMinToRecive, (balanceA - amountToPayA), (balanceB - amountToPayB), fee, govFee) | |
839 | - | let amountWithoutFee = $t03488835288._1 | |
840 | - | let amountWithFee = $t03488835288._2 | |
841 | - | let governanceReward = $t03488835288._3 | |
842 | - | let $t03530536651 = if ((withdrawAsset == assetIdA)) | |
843 | - | then { | |
844 | - | let unstake = if (contains(stakingAssets, strAssetIdA)) | |
845 | - | then invoke(i.caller, "stakeUnstake", [false, ((amountToPayA + amountWithFee) + governanceReward), strAssetIdA], nil) | |
846 | - | else 0 | |
847 | - | if ((unstake == unstake)) | |
848 | - | then $Tuple4((((balanceA - amountToPayA) - amountWithFee) - governanceReward), balanceB, assetIdA, [ScriptTransfer(caller, (amountToPayA + amountWithFee), assetIdA)]) | |
849 | - | else throw("Strict value is not equal to itself.") | |
850 | - | } | |
851 | - | else { | |
852 | - | let unstake = if (contains(stakingAssets, strAssetIdB)) | |
853 | - | then invoke(i.caller, "stakeUnstake", [false, ((amountToPayB + amountWithFee) + governanceReward), strAssetIdB], nil) | |
854 | - | else 0 | |
855 | - | if ((unstake == unstake)) | |
856 | - | then $Tuple4(balanceA, (((balanceB - amountToPayB) - amountWithFee) - governanceReward), assetIdB, [ScriptTransfer(caller, (amountToPayB + amountWithFee), assetIdB)]) | |
857 | - | else throw("Strict value is not equal to itself.") | |
858 | - | } | |
859 | - | let newBalanceA = $t03530536651._1 | |
860 | - | let newBalanceB = $t03530536651._2 | |
861 | - | let govRewardAssetId = $t03530536651._3 | |
862 | - | let userTransfer = $t03530536651._4 | |
863 | - | $Tuple2([ScriptTransfer(i.caller, unlockAmount, shareAssetId)], $Tuple2(([IntegerEntry(kBalanceA, newBalanceA), IntegerEntry(kBalanceB, newBalanceB), IntegerEntry(kShareAssetSupply, (shareAssetSupply - withdrawAmount)), Burn(shareAssetId, withdrawAmount), ScriptTransfer(moneyBoxAddress, governanceReward, govRewardAssetId)] ++ userTransfer), nil)) | |
864 | - | } | |
865 | - | else throw("Strict value is not equal to itself.") | |
866 | - | } | |
867 | - | })) | |
868 | - | ||
869 | - | ||
870 | - | ||
871 | - | @Callable(i) | |
872 | - | func takeIntoAccountExtraFunds (callerBytes,args,pAmounts,pAssetIds) = valueOrElse(isOraclePool(toString(i.caller)), valueOrElse(isActive(), { | |
873 | - | let $t03737637452 = getPoolAssets(i.caller) | |
874 | - | let strAssetIdA = $t03737637452._1 | |
875 | - | let strAssetIdB = $t03737637452._2 | |
876 | - | let assetIdA = $t03737637452._3 | |
877 | - | let assetIdB = $t03737637452._4 | |
878 | - | let $t03746537571 = getPoolBalances(i.caller, assetIdA, assetIdB) | |
879 | - | let balanceA = $t03746537571._1 | |
880 | - | let balanceB = $t03746537571._2 | |
881 | - | let accountBalanceA = $t03746537571._3 | |
882 | - | let accountBalanceB = $t03746537571._4 | |
883 | - | let amountEnrollA = (accountBalanceA - balanceA) | |
884 | - | let amountEnrollB = (accountBalanceB - balanceB) | |
885 | - | if ((size(args) != 0)) | |
886 | - | then throw("Wrong args size") | |
887 | - | else if ((moneyBoxAddress != i.originCaller)) | |
888 | - | then throw("Only the wallet can call this function") | |
889 | - | else if (if ((0 > amountEnrollA)) | |
890 | - | then true | |
891 | - | else (0 > amountEnrollB)) | |
892 | - | then suspend("Enroll amount negative") | |
893 | - | else if (if ((amountEnrollA == 0)) | |
894 | - | then (amountEnrollB == 0) | |
895 | - | else false) | |
896 | - | then throw("No money to take") | |
897 | - | else { | |
898 | - | let stake1 = if (if (contains(stakingAssets, strAssetIdA)) | |
899 | - | then (amountEnrollA > 0) | |
900 | - | else false) | |
901 | - | then invoke(i.caller, "stakeUnstake", [true, amountEnrollA, strAssetIdA], nil) | |
902 | - | else 0 | |
903 | - | if ((stake1 == stake1)) | |
904 | - | then { | |
905 | - | let stake2 = if (if (contains(stakingAssets, strAssetIdB)) | |
906 | - | then (amountEnrollB > 0) | |
907 | - | else false) | |
908 | - | then invoke(i.caller, "stakeUnstake", [true, amountEnrollB, strAssetIdB], nil) | |
909 | - | else 0 | |
910 | - | if ((stake2 == stake2)) | |
911 | - | then $Tuple2(nil, $Tuple2([IntegerEntry(kBalanceA, (balanceA + amountEnrollA)), IntegerEntry(kBalanceB, (balanceB + amountEnrollB))], nil)) | |
912 | - | else throw("Strict value is not equal to itself.") | |
913 | - | } | |
914 | - | else throw("Strict value is not equal to itself.") | |
915 | - | } | |
916 | - | })) | |
293 | + | func exchange (minAmountToReceive) = callCommon("exchange", i.caller.bytes, [toString(minAmountToReceive)], i.payments) | |
917 | 294 | ||
918 | 295 | ||
919 | 296 | @Verifier(tx) | |
920 | 297 | func verify () = { | |
921 | 298 | let multiSignedByAdmins = { | |
922 | 299 | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
923 | 300 | then 1 | |
924 | 301 | else 0 | |
925 | 302 | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
926 | 303 | then 1 | |
927 | 304 | else 0 | |
928 | 305 | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
929 | 306 | then 1 | |
930 | 307 | else 0 | |
931 | 308 | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
932 | 309 | } | |
933 | 310 | multiSignedByAdmins | |
934 | 311 | } | |
935 | 312 |
github/deemru/w8io/169f3d6 111.09 ms ◑