tx · 44QSQ6Sg6oZgzHsCfE4fUs5TizBPBu9auyhe7JdzDdgZ

3NBbSp7yXAeyAmM8uuoenTt3XFfCGQZsHon:  -0.01300000 Waves

2023.05.04 14:18 [2562940] smart account 3NBbSp7yXAeyAmM8uuoenTt3XFfCGQZsHon > SELF 0.00000000 Waves

{ "type": 13, "id": "44QSQ6Sg6oZgzHsCfE4fUs5TizBPBu9auyhe7JdzDdgZ", "fee": 1300000, "feeAssetId": null, "timestamp": 1683199162207, "version": 2, "chainId": 84, "sender": "3NBbSp7yXAeyAmM8uuoenTt3XFfCGQZsHon", "senderPublicKey": "EdMvX1KG6dSSSsAqgamTtbKQho4ZLojCVgcBU4CDSeix", "proofs": [ "3PQ1V44hzMXVBytfVfUhc3B11ryYqVcXAfKyZazrStHP8oWWCX5btfdj2c5LnLE7qjv9GDe3vVNGbKs1RYqNLg5T" ], "script": "base64:BgIXCAISBQoDAQgIEgUKAwEICBIDCgEIEgAXAANTRVACAl9fAAhmZWVTY2FsZQkAtgIBAIDC1y8BD2dldFN0cmluZ09yRmFpbAEDa2V5CQETdmFsdWVPckVycm9yTWVzc2FnZQIJAJ0IAgUEdGhpcwUDa2V5CQCsAgICFU5vIGRhdGEgZm9yIHRoaXMua2V5PQUDa2V5AAxwb29sRGlzYWJsZWQJAAIBAg1Qb29sIGRpc2FibGVkAAxwb29sTm90RXhpc3QJAAIBAhFQb29sIGlzIG5vdCBleGlzdAAOc2xpcHBhZ2VUb29CaWcJAAIBAhNTbGlwcGFnZSBpcyB0b28gYmlnARNrZXlNYW5hZ2VyUHVibGljS2V5AAIUJXNfX21hbmFnZXJQdWJsaWNLZXkBGmtleVBlbmRpbmdNYW5hZ2VyUHVibGljS2V5AAIbJXNfX3BlbmRpbmdNYW5hZ2VyUHVibGljS2V5AQJmYwACEyVzX19mYWN0b3J5Q29udHJhY3QAD2ZhY3RvcnlDb250cmFjdAkBEUBleHRyTmF0aXZlKDEwNjIpAQkBD2dldFN0cmluZ09yRmFpbAEJ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PclVuaXQAAwkAAQIFByRtYXRjaDACCkJ5dGVWZWN0b3IEAnBrBQckbWF0Y2gwBQJwawMJAAECBQckbWF0Y2gwAgRVbml0CAUCdHgPc2VuZGVyUHVibGljS2V5CQACAQILTWF0Y2ggZXJyb3IJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAFD3RhcmdldFB1YmxpY0tleVf/3mw=", "height": 2562940, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3jdi6X77MRCd5erxJQ1tzpwpJqetjbfo3U1ejbNmsAR4 Next: 69unUFWTY6stpkjA9rUkqNCJHKKiKxx5ozz1ZAs4jLYv Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let separator = "__"
4+let SEP = "__"
55
6-let shareAssetDecimals = 8
6+let feeScale = toBigInt(100000000)
77
8-let wavesString = "WAVES"
9-
10-let scale18 = 1000000000000000000
11-
12-let scale18BigInt = toBigInt(scale18)
13-
14-func wrapErr (msg) = makeString(["lp_staking_pools.ride:", msg], " ")
8+func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key))
159
1610
17-func throwErr (msg) = throw(wrapErr(msg))
11+let poolDisabled = throw("Pool disabled")
1812
13+let poolNotExist = throw("Pool is not exist")
1914
20-func errKeyIsNotDefined (address,key) = wrapErr(makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
21-
22-
23-func getStrOrFail (address,key) = valueOrErrorMessage(getString(address, key), errKeyIsNotDefined(address, key))
24-
25-
26-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), errKeyIsNotDefined(address, key))
27-
28-
29-func parseAssetId (input) = if ((input == wavesString))
30- then unit
31- else fromBase58String(input)
32-
33-
34-func assetIdToString (input) = if ((input == unit))
35- then wavesString
36- else toBase58String(value(input))
37-
38-
39-func ensurePositive (v) = if ((v >= 0))
40- then v
41- else throwErr("value should be positive")
42-
43-
44-func keyFactoryContract () = makeString(["%s", "factoryContract"], separator)
45-
46-
47-func keyLpStakingContract () = makeString(["%s", "lpStakingContract"], separator)
48-
49-
50-func keyStakingContract () = makeString(["%s", "stakingContract"], separator)
51-
52-
53-func keyBoostingContract () = makeString(["%s", "boostingContract"], separator)
54-
55-
56-func keySwapContract () = makeString(["%s", "swapContract"], separator)
57-
58-
59-func keyAssetsStoreContract () = makeString(["%s", "assetsStoreContract"], separator)
60-
61-
62-func keyUsdtAssetId () = makeString(["%s", "usdtAssetId"], separator)
63-
64-
65-func keyWxAssetId () = makeString(["%s", "wxAssetId"], separator)
66-
67-
68-func keyShutdown () = makeString(["%s", "shutdown"], separator)
69-
70-
71-func keyMinDelay () = makeString(["%s", "minDelay"], separator)
72-
73-
74-func keyLockFraction () = makeString(["%s", "lockFraction"], separator)
75-
76-
77-func keyShareAssetId (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetId"], separator)
78-
79-
80-func keyBaseAssetId (shareAssetId) = makeString(["%s%s", assetIdToString(shareAssetId), "baseAssetId"], separator)
81-
82-
83-func keyPeriod (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "period"], separator)
84-
85-
86-func keyPeriodStartHeight (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "periodStartHeight", toString(period)], separator)
87-
88-
89-func keyBaseAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "baseAssetAmountToConvert"], separator)
90-
91-
92-func keyShareAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetAmountToConvert"], separator)
93-
94-
95-func keyUserBaseAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert"], separator)
96-
97-
98-func keyUserBaseAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert", "period"], separator)
99-
100-
101-func keyUserShareAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert"], separator)
102-
103-
104-func keyUserShareAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert", "period"], separator)
105-
106-
107-func keyPricePeriod (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "price", toString(period)], separator)
108-
109-
110-func keyPriceHistory (baseAssetId) = makeString(["%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
111-
112-
113-func keyPricePeriodPut (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "put"], separator)
114-
115-
116-func keyPricePutHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "put", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
117-
118-
119-func keyPricePeriodGet (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "get"], separator)
120-
121-
122-func keyPriceGetHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "get", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
123-
124-
125-func keyHistoryEntry (baseAssetId,operation,period,userAddress,txId) = makeString(["%s%s%s%s", "history", operation, toString(userAddress), toBase58String(txId), toString(height)], separator)
126-
15+let slippageTooBig = throw("Slippage is too big")
12716
12817 func keyManagerPublicKey () = "%s__managerPublicKey"
12918
13019
13120 func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
21+
22+
23+func fc () = "%s__factoryContract"
24+
25+
26+let factoryContract = addressFromStringValue(getStringOrFail(fc()))
27+
28+func protocolFee () = makeString(["%s", "protocolFee"], SEP)
29+
30+
31+func poolFee () = makeString(["%s", "poolFee"], SEP)
32+
33+
34+func getStringOrFailFromAddress (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
35+
36+
37+let keyFeeCollectorAddress = "%s__feeCollectorAddress"
38+
39+let feeCollectorAddress = addressFromStringValue(getStringOrFailFromAddress(factoryContract, keyFeeCollectorAddress))
40+
41+func asInt (val) = match val {
42+ case valInt: Int =>
43+ valInt
44+ case _ =>
45+ throw("fail to cast into Int")
46+}
47+
48+
49+func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP)
13250
13351
13452 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
15169 }
15270
15371
154-let permissionDeniedError = throw("Permission denied")
155-
156-func mustThis (i) = if ((i.caller == this))
157- then true
158- else permissionDeniedError
159-
160-
161-func mustManager (i) = match managerPublicKeyOrUnit() {
72+func isManager (i) = match managerPublicKeyOrUnit() {
16273 case pk: ByteVector =>
163- if ((i.callerPublicKey == pk))
164- then true
165- else permissionDeniedError
74+ (i.callerPublicKey == pk)
16675 case _: Unit =>
167- mustThis(i)
76+ (i.caller == this)
16877 case _ =>
16978 throw("Match error")
17079 }
17180
17281
173-let shutdown = valueOrElse(getBoolean(keyShutdown()), false)
174-
175-func shutdownCheck (i) = if (if (!(shutdown))
82+func mustManager (i) = if (isManager(i))
17683 then true
177- else mustManager(i))
178- then true
179- else throw("operation is disabled")
84+ else throw("permission denied")
18085
18186
182-let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract()))
87+func getAccBalance (assetId) = if ((assetId == "WAVES"))
88+ then wavesBalance(this).available
89+ else assetBalance(this, fromBase58String(assetId))
18390
184-let lpStakingContract = addressFromStringValue(getStrOrFail(this, keyLpStakingContract()))
18591
186-let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract()))
187-
188-let boostingContract = addressFromStringValue(getStrOrFail(this, keyBoostingContract()))
189-
190-let swapContract = addressFromStringValue(getStrOrFail(this, keySwapContract()))
191-
192-let assetsStoreContract = addressFromStringValue(getStrOrFail(this, keyAssetsStoreContract()))
193-
194-let usdtAssetId = parseAssetId(getStrOrFail(this, keyUsdtAssetId()))
195-
196-let wxAssetId = parseAssetId(getStrOrFail(this, keyWxAssetId()))
197-
198-let minDelayDefault = 1440
199-
200-let minDelay = valueOrElse(getInteger(this, keyMinDelay()), minDelayDefault)
201-
202-let lockFractionMultiplier = 100000000
203-
204-let lockFractionDefault = fraction(1, lockFractionMultiplier, 2)
205-
206-let lockFraction = valueOrElse(getInteger(this, keyLockFraction()), lockFractionDefault)
207-
208-func getPoolInfo (amountAssetId) = {
209- let amountAssetIdStr = assetIdToString(amountAssetId)
210- let priceAssetIdStr = assetIdToString(usdtAssetId)
211- let poolInfoOption = {
212- let @ = invoke(factoryContract, "poolInfoREADONLY", [amountAssetIdStr, priceAssetIdStr], nil)
213- if ($isInstanceOf(@, "(Address, ByteVector)"))
92+func getPoolAddressAndCheckPoolStatus (assetIn,assetOut) = {
93+ let lpNonReverse = {
94+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
95+ if ($isInstanceOf(@, "String"))
21496 then @
21597 else unit
21698 }
217- poolInfoOption
99+ let lpReverse = {
100+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
101+ if ($isInstanceOf(@, "String"))
102+ then @
103+ else unit
104+ }
105+ let $t025332992 = if ((lpNonReverse != unit))
106+ then {
107+ let pool = {
108+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil)
109+ if ($isInstanceOf(@, "String"))
110+ then @
111+ else throw(($getType(@) + " couldn't be cast to String"))
112+ }
113+ $Tuple2(false, pool)
114+ }
115+ else if ((lpReverse != unit))
116+ then {
117+ let pool = {
118+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil)
119+ if ($isInstanceOf(@, "String"))
120+ then @
121+ else throw(($getType(@) + " couldn't be cast to String"))
122+ }
123+ $Tuple2(true, pool)
124+ }
125+ else poolNotExist
126+ let isReverse = $t025332992._1
127+ let pool = $t025332992._2
128+ let poolStatus = {
129+ let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
130+ if ($isInstanceOf(@, "Int"))
131+ then @
132+ else throw(($getType(@) + " couldn't be cast to Int"))
133+ }
134+ let check = if ((poolStatus == 1))
135+ then true
136+ else poolDisabled
137+ if ((check == check))
138+ then {
139+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
140+ $Tuple2(poolAdr, isReverse)
141+ }
142+ else throw("Strict value is not equal to itself.")
218143 }
219144
220145
221-func calcPrice (lpAssetId,shareAssetId) = {
222- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), "failed to get share asset info")
223- let shareAssetEmission = shareAssetInfo.quantity
224- let stakedAmount = ensurePositive(valueOrErrorMessage({
225- let @ = invoke(stakingContract, "stakedByUserREADONLY", [assetIdToString(lpAssetId), toString(this)], nil)
146+@Callable(i)
147+func swapCalculateREADONLY (amountIn,assetIn,assetOut) = {
148+ let prFee = value(getInteger(protocolFee()))
149+ let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
150+ let plFee = value(getInteger(poolFee()))
151+ let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale)
152+ let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0))
153+ then toBigInt(1)
154+ else feeProtocolAmountCalc
155+ let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0))
156+ then toBigInt(1)
157+ else feePoolAmountCalc
158+ let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount)
159+ let $t039804058 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
160+ let poolAdr = $t039804058._1
161+ let isReverse = $t039804058._2
162+ let res = {
163+ let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse, toInt(feePoolAmount)], nil)
226164 if ($isInstanceOf(@, "Int"))
227165 then @
228- else unit
229- }, wrapErr("invalid stakedByUserREADONLY result")))
230- let price = if ((shareAssetEmission == 0))
231- then scale18BigInt
232- else fraction(toBigInt(stakedAmount), scale18BigInt, toBigInt(shareAssetEmission), FLOOR)
233- price
166+ else throw(($getType(@) + " couldn't be cast to Int"))
167+ }
168+ $Tuple2(nil, res)
234169 }
170+
171+
172+
173+@Callable(i)
174+func swap (amountOutMin,assetOutRaw,addressTo) = {
175+ let assetOut = if ((assetOutRaw == ""))
176+ then "WAVES"
177+ else assetOutRaw
178+ let pmt = value(i.payments[0])
179+ let assetIn = if ((pmt.assetId == unit))
180+ then "WAVES"
181+ else toBase58String(value(pmt.assetId))
182+ let amountIn = value(pmt.amount)
183+ let prFee = value(getInteger(protocolFee()))
184+ let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
185+ let plFee = value(getInteger(poolFee()))
186+ let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale)
187+ let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0))
188+ then toBigInt(1)
189+ else feeProtocolAmountCalc
190+ let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0))
191+ then toBigInt(1)
192+ else feePoolAmountCalc
193+ let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount)
194+ let checks = [if ((size(i.payments) == 1))
195+ then true
196+ else throw("exactly 1 payment are expected")]
197+ if ((checks == checks))
198+ then {
199+ let $t052605338 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
200+ let poolAdr = $t052605338._1
201+ let isReverse = $t052605338._2
202+ let assetInAttachedPayment = if ((assetIn == "WAVES"))
203+ then unit
204+ else fromBase58String(assetIn)
205+ let totalGetRaw = {
206+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo, toInt(feePoolAmount)], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))])
207+ if ($isInstanceOf(@, "Int"))
208+ then @
209+ else throw(($getType(@) + " couldn't be cast to Int"))
210+ }
211+ $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment), ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment)], totalGetRaw)
212+ }
213+ else throw("Strict value is not equal to itself.")
214+ }
215+
235216
236217
237218 @Callable(i)
254235 let pm = pendingManagerPublicKeyOrUnit()
255236 let hasPM = if (isDefined(pm))
256237 then true
257- else throwErr("no pending manager")
238+ else throw("no pending manager")
258239 if ((hasPM == hasPM))
259240 then {
260241 let checkPM = if ((i.callerPublicKey == value(pm)))
261242 then true
262- else throwErr("you are not pending manager")
243+ else throw("you are not pending manager")
263244 if ((checkPM == checkPM))
264245 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
265- else throw("Strict value is not equal to itself.")
266- }
267- else throw("Strict value is not equal to itself.")
268- }
269-
270-
271-
272-@Callable(i)
273-func emit (assetId,amount) = {
274- let checkCaller = mustThis(i)
275- if ((checkCaller == checkCaller))
276- then {
277- let isReissuable = true
278- $Tuple2([Reissue(assetId, amount, isReissuable)], amount)
279- }
280- else throw("Strict value is not equal to itself.")
281- }
282-
283-
284-
285-@Callable(i)
286-func burn (assetId,amount) = {
287- let checkCaller = mustThis(i)
288- if ((checkCaller == checkCaller))
289- then $Tuple2([Burn(assetId, amount)], amount)
290- else throw("Strict value is not equal to itself.")
291- }
292-
293-
294-
295-@Callable(i)
296-func create (baseAssetIdStr,shareAssetIdStr,shareAssetName,shareAssetDescription,shareAssetLogo) = {
297- let shareAssetLabel = "STAKING_LP"
298- let baseAssetId = parseAssetId(baseAssetIdStr)
299- let checks = [mustManager(i), if (isDefined(getPoolInfo(baseAssetId)))
300- then true
301- else throwErr("invalid base asset")]
302- if ((checks == checks))
303- then {
304- let commonState = [IntegerEntry(keyPeriod(baseAssetId), 0)]
305- if ((shareAssetIdStr == ""))
306- then {
307- let shareAssetIssueAmount = 1
308- let shareAssetIssueAction = Issue(shareAssetName, shareAssetDescription, shareAssetIssueAmount, shareAssetDecimals, true)
309- let calculatedShareAssetId = calculateAssetId(shareAssetIssueAction)
310- let shareAssetBurnAction = Burn(calculatedShareAssetId, shareAssetIssueAmount)
311- let calculatedShareAssetIdStr = toBase58String(calculatedShareAssetId)
312- let createOrUpdate = invoke(assetsStoreContract, "createOrUpdate", [calculatedShareAssetIdStr, shareAssetLogo, false], nil)
313- if ((createOrUpdate == createOrUpdate))
314- then {
315- let addLabel = invoke(assetsStoreContract, "addLabel", [calculatedShareAssetIdStr, shareAssetLabel], nil)
316- if ((addLabel == addLabel))
317- then $Tuple2((commonState ++ [shareAssetIssueAction, shareAssetBurnAction, StringEntry(keyShareAssetId(baseAssetId), calculatedShareAssetIdStr), StringEntry(keyBaseAssetId(calculatedShareAssetId), baseAssetIdStr)]), calculatedShareAssetIdStr)
318- else throw("Strict value is not equal to itself.")
319- }
320- else throw("Strict value is not equal to itself.")
321- }
322- else {
323- let shareAssetId = fromBase58String(shareAssetIdStr)
324- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id"))
325- let checkIssuer = if ((shareAssetInfo.issuer == lpStakingContract))
326- then true
327- else throwErr("invalid share asset id issuer")
328- if ((checkIssuer == checkIssuer))
329- then $Tuple2((commonState ++ [StringEntry(keyShareAssetId(baseAssetId), shareAssetIdStr), StringEntry(keyBaseAssetId(shareAssetId), baseAssetIdStr)]), shareAssetIdStr)
330- else throw("Strict value is not equal to itself.")
331- }
332- }
333- else throw("Strict value is not equal to itself.")
334- }
335-
336-
337-
338-@Callable(i)
339-func put () = {
340- let pmt = if ((size(i.payments) == 1))
341- then i.payments[0]
342- else throwErr("exactly 1 payment is expected")
343- let baseAssetId = pmt.assetId
344- let userAddress = i.caller
345- let checks = [shutdownCheck(i), if (isDefined(getString(keyShareAssetId(baseAssetId))))
346- then true
347- else throwErr("invalid asset")]
348- if ((checks == checks))
349- then {
350- let $t01164011743 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
351- let poolAddress = $t01164011743._1
352- let lpAssetId = $t01164011743._2
353- let period = value(getInteger(keyPeriod(baseAssetId)))
354- let userBaseAssetAmountToConvertPeriodOption = getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress))
355- let claimShareAssetInvocation = if ((userBaseAssetAmountToConvertPeriodOption == unit))
356- then unit
357- else {
358- let userBaseAssetAmountToConvertPeriod = value(userBaseAssetAmountToConvertPeriodOption)
359- if ((userBaseAssetAmountToConvertPeriod == period))
360- then unit
361- else invoke(this, "claimShareAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil)
362- }
363- if ((claimShareAssetInvocation == claimShareAssetInvocation))
364- then {
365- let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0)
366- let userBaseAssetAmountToConvert = valueOrElse(getInteger(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress)), 0)
367- $Tuple2([IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), (baseAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), (userBaseAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "put", period, userAddress, i.transactionId), makeString([toString(pmt.amount), toString(lastBlock.timestamp), toString(userBaseAssetAmountToConvert)], separator))], unit)
368- }
369- else throw("Strict value is not equal to itself.")
370- }
371- else throw("Strict value is not equal to itself.")
372- }
373-
374-
375-
376-@Callable(i)
377-func claimShareAsset (baseAssetIdStr,userAddressStr) = {
378- let checks = [shutdownCheck(i)]
379- if ((checks == checks))
380- then {
381- let userAddress = if ((userAddressStr == ""))
382- then i.caller
383- else {
384- let checkCaller = mustThis(i)
385- if ((checkCaller == checkCaller))
386- then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
387- else throw("Strict value is not equal to itself.")
388- }
389- if ((userAddress == userAddress))
390- then {
391- let baseAssetId = parseAssetId(baseAssetIdStr)
392- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
393- if ((shareAssetId == shareAssetId))
394- then {
395- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
396- if ((period == period))
397- then {
398- let userBaseAssetAmountToConvert = valueOrElse(getInteger(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress)), 0)
399- let checkAmountToConvert = if ((userBaseAssetAmountToConvert > 0))
400- then true
401- else throwErr("nothing to claim")
402- if ((checkAmountToConvert == checkAmountToConvert))
403- then {
404- let userBaseAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period"))
405- let checkPeriod = if ((period > userBaseAssetAmountToConvertPeriod))
406- then true
407- else throwErr("invalid period")
408- if ((checkPeriod == checkPeriod))
409- then {
410- let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodPut(baseAssetId, userBaseAssetAmountToConvertPeriod)), wrapErr("failed to get price")))
411- let shareAssetAmount = toInt(fraction(toBigInt(userBaseAssetAmountToConvert), scale18BigInt, price))
412- $Tuple2([IntegerEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), 0), DeleteEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, shareAssetAmount, shareAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimShareAsset", period, userAddress, i.transactionId), makeString([toString(shareAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userBaseAssetAmountToConvert)], separator))], unit)
413- }
414- else throw("Strict value is not equal to itself.")
415- }
416- else throw("Strict value is not equal to itself.")
417- }
418- else throw("Strict value is not equal to itself.")
419- }
420- else throw("Strict value is not equal to itself.")
421- }
422- else throw("Strict value is not equal to itself.")
423- }
424- else throw("Strict value is not equal to itself.")
425- }
426-
427-
428-
429-@Callable(i)
430-func get () = {
431- let checks = [shutdownCheck(i)]
432- if ((checks == checks))
433- then {
434- let pmt = if ((size(i.payments) == 1))
435- then i.payments[0]
436- else throwErr("exactly 1 payment is expected")
437- let shareAssetId = pmt.assetId
438- let baseAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyBaseAssetId(shareAssetId)), wrapErr("invalid share asset id"))))
439- if ((baseAssetId == baseAssetId))
440- then {
441- let userAddress = i.caller
442- let $t01582016009 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
443- let poolAddress = $t01582016009._1
444- let lpAssetId = $t01582016009._2
445- let period = value(getInteger(keyPeriod(baseAssetId)))
446- let userShareAssetAmountToConvertPeriodOption = getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress))
447- let claimBaseAssetInvocation = if ((userShareAssetAmountToConvertPeriodOption == unit))
448- then unit
449- else {
450- let userShareAssetAmountToConvertPeriod = value(userShareAssetAmountToConvertPeriodOption)
451- if ((userShareAssetAmountToConvertPeriod == period))
452- then unit
453- else invoke(this, "claimBaseAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil)
454- }
455- if ((claimBaseAssetInvocation == claimBaseAssetInvocation))
456- then {
457- let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0)
458- let userShareAssetAmountToConvert = valueOrElse(getInteger(keyUserShareAssetAmountToConvert(baseAssetId, userAddress)), 0)
459- $Tuple2([IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), (shareAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), (userShareAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "get", period, userAddress, i.transactionId), makeString([toString(pmt.amount), toString(lastBlock.timestamp), toString(userShareAssetAmountToConvert)], separator))], unit)
460- }
461- else throw("Strict value is not equal to itself.")
462- }
463- else throw("Strict value is not equal to itself.")
464- }
465- else throw("Strict value is not equal to itself.")
466- }
467-
468-
469-
470-@Callable(i)
471-func claimBaseAsset (baseAssetIdStr,userAddressStr) = {
472- let checks = [shutdownCheck(i)]
473- if ((checks == checks))
474- then {
475- let userAddress = if ((userAddressStr == ""))
476- then i.caller
477- else {
478- let checkCaller = mustThis(i)
479- if ((checkCaller == checkCaller))
480- then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
481- else throw("Strict value is not equal to itself.")
482- }
483- if ((userAddress == userAddress))
484- then {
485- let baseAssetId = parseAssetId(baseAssetIdStr)
486- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
487- if ((shareAssetId == shareAssetId))
488- then {
489- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
490- if ((period == period))
491- then {
492- let userShareAssetAmountToConvert = valueOrElse(getInteger(keyUserShareAssetAmountToConvert(baseAssetId, userAddress)), 0)
493- let userShareAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period"))
494- let checkPeriod = if ((period > userShareAssetAmountToConvertPeriod))
495- then true
496- else throwErr("invalid period")
497- if ((checkPeriod == checkPeriod))
498- then {
499- let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodGet(baseAssetId, userShareAssetAmountToConvertPeriod)), wrapErr("failed to get price")))
500- let baseAssetAmount = toInt(fraction(toBigInt(userShareAssetAmountToConvert), price, scale18BigInt))
501- $Tuple2([IntegerEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), 0), DeleteEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, baseAssetAmount, baseAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimBaseAsset", period, userAddress, i.transactionId), makeString([toString(baseAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userShareAssetAmountToConvertPeriod)], separator))], unit)
502- }
503- else throw("Strict value is not equal to itself.")
504- }
505- else throw("Strict value is not equal to itself.")
506- }
507- else throw("Strict value is not equal to itself.")
508- }
509- else throw("Strict value is not equal to itself.")
510- }
511- else throw("Strict value is not equal to itself.")
512- }
513-
514-
515-
516-@Callable(i)
517-func finalize (baseAssetIdStr) = {
518- let checks = [shutdownCheck(i)]
519- if ((checks == checks))
520- then {
521- let baseAssetId = parseAssetId(baseAssetIdStr)
522- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
523- if ((shareAssetId == shareAssetId))
524- then {
525- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id"))
526- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
527- if ((period == period))
528- then {
529- let periodStartHeightOption = getInteger(keyPeriodStartHeight(baseAssetId, period))
530- let checkDelay = if ((periodStartHeightOption == unit))
531- then unit
532- else {
533- let delay = (height - value(periodStartHeightOption))
534- let blocksToWait = max([0, (minDelay - delay)])
535- if ((blocksToWait == 0))
536- then unit
537- else throwErr(makeString(["finalization will be possible in ", toString(blocksToWait), " blocks"], ""))
538- }
539- if ((checkDelay == checkDelay))
540- then {
541- let $t02111321294 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
542- let poolAddress = $t02111321294._1
543- let lpAssetId = $t02111321294._2
544- let stakingReward = valueOrErrorMessage({
545- let @ = invoke(stakingContract, "claimWxDoNotThrow", [assetIdToString(lpAssetId)], nil)
546- if ($isInstanceOf(@, "Int"))
547- then @
548- else unit
549- }, wrapErr("invalid claimWx result"))
550- if ((stakingReward == stakingReward))
551- then {
552- let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0)
553- let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0)
554- let checkFinalizationIsRequired = {
555- let isFinalizationRequired = if (if ((stakingReward > 0))
556- then true
557- else (baseAssetAmountToConvert > 0))
558- then true
559- else (shareAssetAmountToConvert > 0)
560- if (isFinalizationRequired)
561- then true
562- else throwErr("nothing to finalize")
563- }
564- if ((checkFinalizationIsRequired == checkFinalizationIsRequired))
565- then {
566- let useStakingReward = if ((stakingReward > 0))
567- then {
568- let lockPart = fraction(stakingReward, lockFraction, lockFractionMultiplier)
569- let convertPart = (stakingReward - lockPart)
570- let r = invoke(boostingContract, "userMaxDurationREADONLY", [toString(this)], nil)
571- let lock = if ((lockPart > 0))
572- then match r {
573- case _ =>
574- if (if (if ($isInstanceOf($match0._1, "String"))
575- then $isInstanceOf($match0._2, "Int")
576- else false)
577- then $isInstanceOf($match0, "(String, Int)")
578- else false)
579- then {
580- let function = $match0._1
581- let duration = $match0._2
582- if ((lockPart > 0))
583- then invoke(boostingContract, function, [duration], [AttachedPayment(wxAssetId, lockPart)])
584- else unit
585- }
586- else throwErr("invalid lock params")
587- }
588- else unit
589- if ((lock == lock))
590- then {
591- let convertedAmount = if ((convertPart > 0))
592- then {
593- let inAssetId = wxAssetId
594- let minimumToReceive = 0
595- let outAssetIdStr = assetIdToString(usdtAssetId)
596- let targetAddress = toString(this)
597- valueOrErrorMessage({
598- let @ = invoke(swapContract, "swap", [minimumToReceive, outAssetIdStr, targetAddress], [AttachedPayment(inAssetId, convertPart)])
599- if ($isInstanceOf(@, "Int"))
600- then @
601- else unit
602- }, wrapErr("invalid swap result"))
603- }
604- else 0
605- if ((convertedAmount == convertedAmount))
606- then {
607- let lpAssetAmount = if ((convertedAmount > 0))
608- then {
609- let minOutAmount = 0
610- let autoStake = true
611- valueOrErrorMessage({
612- let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(usdtAssetId, convertedAmount)])
613- if ($isInstanceOf(@, "Int"))
614- then @
615- else unit
616- }, wrapErr("invalid putOneTknV2 result"))
617- }
618- else 0
619- if ((lpAssetAmount == lpAssetAmount))
620- then lpAssetAmount
621- else throw("Strict value is not equal to itself.")
622- }
623- else throw("Strict value is not equal to itself.")
624- }
625- else throw("Strict value is not equal to itself.")
626- }
627- else unit
628- if ((useStakingReward == useStakingReward))
629- then {
630- let getActions = if ((shareAssetAmountToConvert > 0))
631- then {
632- let price = calcPrice(lpAssetId, shareAssetId)
633- if ((price == price))
634- then {
635- let unstakeAmount = toInt(fraction(toBigInt(shareAssetAmountToConvert), price, scale18BigInt, FLOOR))
636- let baseAssetAmount = {
637- let outAssetId = baseAssetId
638- let minOutAmount = 0
639- valueOrErrorMessage({
640- let @ = invoke(poolAddress, "unstakeAndGetOneTknV2", [unstakeAmount, assetIdToString(outAssetId), minOutAmount], nil)
641- if ($isInstanceOf(@, "Int"))
642- then @
643- else unit
644- }, wrapErr("invalid unstakeAndGetOneTknV2 result"))
645- }
646- if ((baseAssetAmount == baseAssetAmount))
647- then {
648- let shareAssetBurn = if ((shareAssetInfo.issuer == this))
649- then invoke(this, "burn", [shareAssetId, shareAssetAmountToConvert], nil)
650- else throwErr("invalid share asset issuer")
651- if ((shareAssetBurn == shareAssetBurn))
652- then {
653- let priceGet = fraction(toBigInt(baseAssetAmount), scale18BigInt, toBigInt(shareAssetAmountToConvert), FLOOR)
654- let priceGetUpdateActions = [BinaryEntry(keyPricePeriodGet(baseAssetId, period), toBytes(priceGet)), StringEntry(keyPriceGetHistory(baseAssetId), toString(priceGet))]
655- priceGetUpdateActions
656- }
657- else throw("Strict value is not equal to itself.")
658- }
659- else throw("Strict value is not equal to itself.")
660- }
661- else throw("Strict value is not equal to itself.")
662- }
663- else nil
664- if ((getActions == getActions))
665- then {
666- let putActions = if ((baseAssetAmountToConvert > 0))
667- then {
668- let lpAssetAmount = {
669- let minOutAmount = 0
670- let autoStake = true
671- valueOrErrorMessage({
672- let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(baseAssetId, baseAssetAmountToConvert)])
673- if ($isInstanceOf(@, "Int"))
674- then @
675- else unit
676- }, wrapErr("invalid putOneTknV2 result"))
677- }
678- if ((lpAssetAmount == lpAssetAmount))
679- then {
680- let price = calcPrice(lpAssetId, shareAssetId)
681- if ((price == price))
682- then {
683- let checkPrice = if ((value(toInt(price)) != 0))
684- then true
685- else throw("price is ZERO")
686- if ((checkPrice == checkPrice))
687- then {
688- let shareAssetAmount = toInt(fraction(toBigInt(lpAssetAmount), scale18BigInt, price, FLOOR))
689- let checkShareAssetAmount = if ((value(toInt(price)) != 0))
690- then true
691- else throw("shareAssetAmount is ZERO")
692- if ((checkShareAssetAmount == checkShareAssetAmount))
693- then {
694- let shareAssetReissue = if ((shareAssetInfo.issuer == this))
695- then invoke(this, "emit", [shareAssetId, shareAssetAmount], nil)
696- else throwErr("invalid share asset issuer")
697- if ((shareAssetReissue == shareAssetReissue))
698- then {
699- let pricePut = fraction(toBigInt(baseAssetAmountToConvert), scale18BigInt, toBigInt(shareAssetAmount))
700- let pricePutUpdateActions = [BinaryEntry(keyPricePeriodPut(baseAssetId, period), toBytes(pricePut)), StringEntry(keyPricePutHistory(baseAssetId), toString(pricePut))]
701- pricePutUpdateActions
702- }
703- else throw("Strict value is not equal to itself.")
704- }
705- else throw("Strict value is not equal to itself.")
706- }
707- else throw("Strict value is not equal to itself.")
708- }
709- else throw("Strict value is not equal to itself.")
710- }
711- else throw("Strict value is not equal to itself.")
712- }
713- else nil
714- if ((putActions == putActions))
715- then {
716- let newPeriod = (period + 1)
717- let lastPrice = calcPrice(lpAssetId, shareAssetId)
718- let actions = (([IntegerEntry(keyPeriod(baseAssetId), newPeriod), IntegerEntry(keyPeriodStartHeight(baseAssetId, newPeriod), height), IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), 0), IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), 0), BinaryEntry(keyPricePeriod(baseAssetId, period), toBytes(lastPrice)), StringEntry(keyPriceHistory(baseAssetId), toString(lastPrice))] ++ putActions) ++ getActions)
719- $Tuple2(actions, toBytes(lastPrice))
720- }
721- else throw("Strict value is not equal to itself.")
722- }
723- else throw("Strict value is not equal to itself.")
724- }
725- else throw("Strict value is not equal to itself.")
726- }
727- else throw("Strict value is not equal to itself.")
728- }
729- else throw("Strict value is not equal to itself.")
730- }
731- else throw("Strict value is not equal to itself.")
732- }
733- else throw("Strict value is not equal to itself.")
734- }
735246 else throw("Strict value is not equal to itself.")
736247 }
737248 else throw("Strict value is not equal to itself.")
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let separator = "__"
4+let SEP = "__"
55
6-let shareAssetDecimals = 8
6+let feeScale = toBigInt(100000000)
77
8-let wavesString = "WAVES"
9-
10-let scale18 = 1000000000000000000
11-
12-let scale18BigInt = toBigInt(scale18)
13-
14-func wrapErr (msg) = makeString(["lp_staking_pools.ride:", msg], " ")
8+func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key))
159
1610
17-func throwErr (msg) = throw(wrapErr(msg))
11+let poolDisabled = throw("Pool disabled")
1812
13+let poolNotExist = throw("Pool is not exist")
1914
20-func errKeyIsNotDefined (address,key) = wrapErr(makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
21-
22-
23-func getStrOrFail (address,key) = valueOrErrorMessage(getString(address, key), errKeyIsNotDefined(address, key))
24-
25-
26-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), errKeyIsNotDefined(address, key))
27-
28-
29-func parseAssetId (input) = if ((input == wavesString))
30- then unit
31- else fromBase58String(input)
32-
33-
34-func assetIdToString (input) = if ((input == unit))
35- then wavesString
36- else toBase58String(value(input))
37-
38-
39-func ensurePositive (v) = if ((v >= 0))
40- then v
41- else throwErr("value should be positive")
42-
43-
44-func keyFactoryContract () = makeString(["%s", "factoryContract"], separator)
45-
46-
47-func keyLpStakingContract () = makeString(["%s", "lpStakingContract"], separator)
48-
49-
50-func keyStakingContract () = makeString(["%s", "stakingContract"], separator)
51-
52-
53-func keyBoostingContract () = makeString(["%s", "boostingContract"], separator)
54-
55-
56-func keySwapContract () = makeString(["%s", "swapContract"], separator)
57-
58-
59-func keyAssetsStoreContract () = makeString(["%s", "assetsStoreContract"], separator)
60-
61-
62-func keyUsdtAssetId () = makeString(["%s", "usdtAssetId"], separator)
63-
64-
65-func keyWxAssetId () = makeString(["%s", "wxAssetId"], separator)
66-
67-
68-func keyShutdown () = makeString(["%s", "shutdown"], separator)
69-
70-
71-func keyMinDelay () = makeString(["%s", "minDelay"], separator)
72-
73-
74-func keyLockFraction () = makeString(["%s", "lockFraction"], separator)
75-
76-
77-func keyShareAssetId (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetId"], separator)
78-
79-
80-func keyBaseAssetId (shareAssetId) = makeString(["%s%s", assetIdToString(shareAssetId), "baseAssetId"], separator)
81-
82-
83-func keyPeriod (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "period"], separator)
84-
85-
86-func keyPeriodStartHeight (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "periodStartHeight", toString(period)], separator)
87-
88-
89-func keyBaseAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "baseAssetAmountToConvert"], separator)
90-
91-
92-func keyShareAssetAmountToConvert (baseAssetId) = makeString(["%s%s", assetIdToString(baseAssetId), "shareAssetAmountToConvert"], separator)
93-
94-
95-func keyUserBaseAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert"], separator)
96-
97-
98-func keyUserBaseAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "baseAssetAmountToConvert", "period"], separator)
99-
100-
101-func keyUserShareAssetAmountToConvert (baseAssetId,userAddress) = makeString(["%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert"], separator)
102-
103-
104-func keyUserShareAssetAmountToConvertPeriod (baseAssetId,userAddress) = makeString(["%s%s%s%s", assetIdToString(baseAssetId), toString(userAddress), "shareAssetAmountToConvert", "period"], separator)
105-
106-
107-func keyPricePeriod (baseAssetId,period) = makeString(["%s%s%d", assetIdToString(baseAssetId), "price", toString(period)], separator)
108-
109-
110-func keyPriceHistory (baseAssetId) = makeString(["%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
111-
112-
113-func keyPricePeriodPut (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "put"], separator)
114-
115-
116-func keyPricePutHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "put", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
117-
118-
119-func keyPricePeriodGet (baseAssetId,period) = makeString(["%s%s%d%s", assetIdToString(baseAssetId), "price", toString(period), "get"], separator)
120-
121-
122-func keyPriceGetHistory (baseAssetId) = makeString(["%s%s%s%s%d%d", assetIdToString(baseAssetId), "price", "history", "get", toString(lastBlock.height), toString(lastBlock.timestamp)], separator)
123-
124-
125-func keyHistoryEntry (baseAssetId,operation,period,userAddress,txId) = makeString(["%s%s%s%s", "history", operation, toString(userAddress), toBase58String(txId), toString(height)], separator)
126-
15+let slippageTooBig = throw("Slippage is too big")
12716
12817 func keyManagerPublicKey () = "%s__managerPublicKey"
12918
13019
13120 func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
21+
22+
23+func fc () = "%s__factoryContract"
24+
25+
26+let factoryContract = addressFromStringValue(getStringOrFail(fc()))
27+
28+func protocolFee () = makeString(["%s", "protocolFee"], SEP)
29+
30+
31+func poolFee () = makeString(["%s", "poolFee"], SEP)
32+
33+
34+func getStringOrFailFromAddress (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], ""))
35+
36+
37+let keyFeeCollectorAddress = "%s__feeCollectorAddress"
38+
39+let feeCollectorAddress = addressFromStringValue(getStringOrFailFromAddress(factoryContract, keyFeeCollectorAddress))
40+
41+func asInt (val) = match val {
42+ case valInt: Int =>
43+ valInt
44+ case _ =>
45+ throw("fail to cast into Int")
46+}
47+
48+
49+func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP)
13250
13351
13452 func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
13553 case s: String =>
13654 fromBase58String(s)
13755 case _: Unit =>
13856 unit
13957 case _ =>
14058 throw("Match error")
14159 }
14260
14361
14462 func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
14563 case s: String =>
14664 fromBase58String(s)
14765 case _: Unit =>
14866 unit
14967 case _ =>
15068 throw("Match error")
15169 }
15270
15371
154-let permissionDeniedError = throw("Permission denied")
155-
156-func mustThis (i) = if ((i.caller == this))
157- then true
158- else permissionDeniedError
159-
160-
161-func mustManager (i) = match managerPublicKeyOrUnit() {
72+func isManager (i) = match managerPublicKeyOrUnit() {
16273 case pk: ByteVector =>
163- if ((i.callerPublicKey == pk))
164- then true
165- else permissionDeniedError
74+ (i.callerPublicKey == pk)
16675 case _: Unit =>
167- mustThis(i)
76+ (i.caller == this)
16877 case _ =>
16978 throw("Match error")
17079 }
17180
17281
173-let shutdown = valueOrElse(getBoolean(keyShutdown()), false)
174-
175-func shutdownCheck (i) = if (if (!(shutdown))
82+func mustManager (i) = if (isManager(i))
17683 then true
177- else mustManager(i))
178- then true
179- else throw("operation is disabled")
84+ else throw("permission denied")
18085
18186
182-let factoryContract = addressFromStringValue(getStrOrFail(this, keyFactoryContract()))
87+func getAccBalance (assetId) = if ((assetId == "WAVES"))
88+ then wavesBalance(this).available
89+ else assetBalance(this, fromBase58String(assetId))
18390
184-let lpStakingContract = addressFromStringValue(getStrOrFail(this, keyLpStakingContract()))
18591
186-let stakingContract = addressFromStringValue(getStrOrFail(this, keyStakingContract()))
187-
188-let boostingContract = addressFromStringValue(getStrOrFail(this, keyBoostingContract()))
189-
190-let swapContract = addressFromStringValue(getStrOrFail(this, keySwapContract()))
191-
192-let assetsStoreContract = addressFromStringValue(getStrOrFail(this, keyAssetsStoreContract()))
193-
194-let usdtAssetId = parseAssetId(getStrOrFail(this, keyUsdtAssetId()))
195-
196-let wxAssetId = parseAssetId(getStrOrFail(this, keyWxAssetId()))
197-
198-let minDelayDefault = 1440
199-
200-let minDelay = valueOrElse(getInteger(this, keyMinDelay()), minDelayDefault)
201-
202-let lockFractionMultiplier = 100000000
203-
204-let lockFractionDefault = fraction(1, lockFractionMultiplier, 2)
205-
206-let lockFraction = valueOrElse(getInteger(this, keyLockFraction()), lockFractionDefault)
207-
208-func getPoolInfo (amountAssetId) = {
209- let amountAssetIdStr = assetIdToString(amountAssetId)
210- let priceAssetIdStr = assetIdToString(usdtAssetId)
211- let poolInfoOption = {
212- let @ = invoke(factoryContract, "poolInfoREADONLY", [amountAssetIdStr, priceAssetIdStr], nil)
213- if ($isInstanceOf(@, "(Address, ByteVector)"))
92+func getPoolAddressAndCheckPoolStatus (assetIn,assetOut) = {
93+ let lpNonReverse = {
94+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil)
95+ if ($isInstanceOf(@, "String"))
21496 then @
21597 else unit
21698 }
217- poolInfoOption
99+ let lpReverse = {
100+ let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil)
101+ if ($isInstanceOf(@, "String"))
102+ then @
103+ else unit
104+ }
105+ let $t025332992 = if ((lpNonReverse != unit))
106+ then {
107+ let pool = {
108+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil)
109+ if ($isInstanceOf(@, "String"))
110+ then @
111+ else throw(($getType(@) + " couldn't be cast to String"))
112+ }
113+ $Tuple2(false, pool)
114+ }
115+ else if ((lpReverse != unit))
116+ then {
117+ let pool = {
118+ let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil)
119+ if ($isInstanceOf(@, "String"))
120+ then @
121+ else throw(($getType(@) + " couldn't be cast to String"))
122+ }
123+ $Tuple2(true, pool)
124+ }
125+ else poolNotExist
126+ let isReverse = $t025332992._1
127+ let pool = $t025332992._2
128+ let poolStatus = {
129+ let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil)
130+ if ($isInstanceOf(@, "Int"))
131+ then @
132+ else throw(($getType(@) + " couldn't be cast to Int"))
133+ }
134+ let check = if ((poolStatus == 1))
135+ then true
136+ else poolDisabled
137+ if ((check == check))
138+ then {
139+ let poolAdr = addressFromStringValue(valueOrElse(pool, ""))
140+ $Tuple2(poolAdr, isReverse)
141+ }
142+ else throw("Strict value is not equal to itself.")
218143 }
219144
220145
221-func calcPrice (lpAssetId,shareAssetId) = {
222- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), "failed to get share asset info")
223- let shareAssetEmission = shareAssetInfo.quantity
224- let stakedAmount = ensurePositive(valueOrErrorMessage({
225- let @ = invoke(stakingContract, "stakedByUserREADONLY", [assetIdToString(lpAssetId), toString(this)], nil)
146+@Callable(i)
147+func swapCalculateREADONLY (amountIn,assetIn,assetOut) = {
148+ let prFee = value(getInteger(protocolFee()))
149+ let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
150+ let plFee = value(getInteger(poolFee()))
151+ let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale)
152+ let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0))
153+ then toBigInt(1)
154+ else feeProtocolAmountCalc
155+ let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0))
156+ then toBigInt(1)
157+ else feePoolAmountCalc
158+ let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount)
159+ let $t039804058 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
160+ let poolAdr = $t039804058._1
161+ let isReverse = $t039804058._2
162+ let res = {
163+ let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse, toInt(feePoolAmount)], nil)
226164 if ($isInstanceOf(@, "Int"))
227165 then @
228- else unit
229- }, wrapErr("invalid stakedByUserREADONLY result")))
230- let price = if ((shareAssetEmission == 0))
231- then scale18BigInt
232- else fraction(toBigInt(stakedAmount), scale18BigInt, toBigInt(shareAssetEmission), FLOOR)
233- price
166+ else throw(($getType(@) + " couldn't be cast to Int"))
167+ }
168+ $Tuple2(nil, res)
234169 }
170+
171+
172+
173+@Callable(i)
174+func swap (amountOutMin,assetOutRaw,addressTo) = {
175+ let assetOut = if ((assetOutRaw == ""))
176+ then "WAVES"
177+ else assetOutRaw
178+ let pmt = value(i.payments[0])
179+ let assetIn = if ((pmt.assetId == unit))
180+ then "WAVES"
181+ else toBase58String(value(pmt.assetId))
182+ let amountIn = value(pmt.amount)
183+ let prFee = value(getInteger(protocolFee()))
184+ let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale)
185+ let plFee = value(getInteger(poolFee()))
186+ let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale)
187+ let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0))
188+ then toBigInt(1)
189+ else feeProtocolAmountCalc
190+ let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0))
191+ then toBigInt(1)
192+ else feePoolAmountCalc
193+ let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount)
194+ let checks = [if ((size(i.payments) == 1))
195+ then true
196+ else throw("exactly 1 payment are expected")]
197+ if ((checks == checks))
198+ then {
199+ let $t052605338 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut)
200+ let poolAdr = $t052605338._1
201+ let isReverse = $t052605338._2
202+ let assetInAttachedPayment = if ((assetIn == "WAVES"))
203+ then unit
204+ else fromBase58String(assetIn)
205+ let totalGetRaw = {
206+ let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, addressTo, toInt(feePoolAmount)], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))])
207+ if ($isInstanceOf(@, "Int"))
208+ then @
209+ else throw(($getType(@) + " couldn't be cast to Int"))
210+ }
211+ $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment), ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment)], totalGetRaw)
212+ }
213+ else throw("Strict value is not equal to itself.")
214+ }
215+
235216
236217
237218 @Callable(i)
238219 func setManager (pendingManagerPublicKey) = {
239220 let checkCaller = mustManager(i)
240221 if ((checkCaller == checkCaller))
241222 then {
242223 let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
243224 if ((checkManagerPublicKey == checkManagerPublicKey))
244225 then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
245226 else throw("Strict value is not equal to itself.")
246227 }
247228 else throw("Strict value is not equal to itself.")
248229 }
249230
250231
251232
252233 @Callable(i)
253234 func confirmManager () = {
254235 let pm = pendingManagerPublicKeyOrUnit()
255236 let hasPM = if (isDefined(pm))
256237 then true
257- else throwErr("no pending manager")
238+ else throw("no pending manager")
258239 if ((hasPM == hasPM))
259240 then {
260241 let checkPM = if ((i.callerPublicKey == value(pm)))
261242 then true
262- else throwErr("you are not pending manager")
243+ else throw("you are not pending manager")
263244 if ((checkPM == checkPM))
264245 then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
265- else throw("Strict value is not equal to itself.")
266- }
267- else throw("Strict value is not equal to itself.")
268- }
269-
270-
271-
272-@Callable(i)
273-func emit (assetId,amount) = {
274- let checkCaller = mustThis(i)
275- if ((checkCaller == checkCaller))
276- then {
277- let isReissuable = true
278- $Tuple2([Reissue(assetId, amount, isReissuable)], amount)
279- }
280- else throw("Strict value is not equal to itself.")
281- }
282-
283-
284-
285-@Callable(i)
286-func burn (assetId,amount) = {
287- let checkCaller = mustThis(i)
288- if ((checkCaller == checkCaller))
289- then $Tuple2([Burn(assetId, amount)], amount)
290- else throw("Strict value is not equal to itself.")
291- }
292-
293-
294-
295-@Callable(i)
296-func create (baseAssetIdStr,shareAssetIdStr,shareAssetName,shareAssetDescription,shareAssetLogo) = {
297- let shareAssetLabel = "STAKING_LP"
298- let baseAssetId = parseAssetId(baseAssetIdStr)
299- let checks = [mustManager(i), if (isDefined(getPoolInfo(baseAssetId)))
300- then true
301- else throwErr("invalid base asset")]
302- if ((checks == checks))
303- then {
304- let commonState = [IntegerEntry(keyPeriod(baseAssetId), 0)]
305- if ((shareAssetIdStr == ""))
306- then {
307- let shareAssetIssueAmount = 1
308- let shareAssetIssueAction = Issue(shareAssetName, shareAssetDescription, shareAssetIssueAmount, shareAssetDecimals, true)
309- let calculatedShareAssetId = calculateAssetId(shareAssetIssueAction)
310- let shareAssetBurnAction = Burn(calculatedShareAssetId, shareAssetIssueAmount)
311- let calculatedShareAssetIdStr = toBase58String(calculatedShareAssetId)
312- let createOrUpdate = invoke(assetsStoreContract, "createOrUpdate", [calculatedShareAssetIdStr, shareAssetLogo, false], nil)
313- if ((createOrUpdate == createOrUpdate))
314- then {
315- let addLabel = invoke(assetsStoreContract, "addLabel", [calculatedShareAssetIdStr, shareAssetLabel], nil)
316- if ((addLabel == addLabel))
317- then $Tuple2((commonState ++ [shareAssetIssueAction, shareAssetBurnAction, StringEntry(keyShareAssetId(baseAssetId), calculatedShareAssetIdStr), StringEntry(keyBaseAssetId(calculatedShareAssetId), baseAssetIdStr)]), calculatedShareAssetIdStr)
318- else throw("Strict value is not equal to itself.")
319- }
320- else throw("Strict value is not equal to itself.")
321- }
322- else {
323- let shareAssetId = fromBase58String(shareAssetIdStr)
324- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id"))
325- let checkIssuer = if ((shareAssetInfo.issuer == lpStakingContract))
326- then true
327- else throwErr("invalid share asset id issuer")
328- if ((checkIssuer == checkIssuer))
329- then $Tuple2((commonState ++ [StringEntry(keyShareAssetId(baseAssetId), shareAssetIdStr), StringEntry(keyBaseAssetId(shareAssetId), baseAssetIdStr)]), shareAssetIdStr)
330- else throw("Strict value is not equal to itself.")
331- }
332- }
333- else throw("Strict value is not equal to itself.")
334- }
335-
336-
337-
338-@Callable(i)
339-func put () = {
340- let pmt = if ((size(i.payments) == 1))
341- then i.payments[0]
342- else throwErr("exactly 1 payment is expected")
343- let baseAssetId = pmt.assetId
344- let userAddress = i.caller
345- let checks = [shutdownCheck(i), if (isDefined(getString(keyShareAssetId(baseAssetId))))
346- then true
347- else throwErr("invalid asset")]
348- if ((checks == checks))
349- then {
350- let $t01164011743 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
351- let poolAddress = $t01164011743._1
352- let lpAssetId = $t01164011743._2
353- let period = value(getInteger(keyPeriod(baseAssetId)))
354- let userBaseAssetAmountToConvertPeriodOption = getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress))
355- let claimShareAssetInvocation = if ((userBaseAssetAmountToConvertPeriodOption == unit))
356- then unit
357- else {
358- let userBaseAssetAmountToConvertPeriod = value(userBaseAssetAmountToConvertPeriodOption)
359- if ((userBaseAssetAmountToConvertPeriod == period))
360- then unit
361- else invoke(this, "claimShareAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil)
362- }
363- if ((claimShareAssetInvocation == claimShareAssetInvocation))
364- then {
365- let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0)
366- let userBaseAssetAmountToConvert = valueOrElse(getInteger(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress)), 0)
367- $Tuple2([IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), (baseAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), (userBaseAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "put", period, userAddress, i.transactionId), makeString([toString(pmt.amount), toString(lastBlock.timestamp), toString(userBaseAssetAmountToConvert)], separator))], unit)
368- }
369- else throw("Strict value is not equal to itself.")
370- }
371- else throw("Strict value is not equal to itself.")
372- }
373-
374-
375-
376-@Callable(i)
377-func claimShareAsset (baseAssetIdStr,userAddressStr) = {
378- let checks = [shutdownCheck(i)]
379- if ((checks == checks))
380- then {
381- let userAddress = if ((userAddressStr == ""))
382- then i.caller
383- else {
384- let checkCaller = mustThis(i)
385- if ((checkCaller == checkCaller))
386- then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
387- else throw("Strict value is not equal to itself.")
388- }
389- if ((userAddress == userAddress))
390- then {
391- let baseAssetId = parseAssetId(baseAssetIdStr)
392- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
393- if ((shareAssetId == shareAssetId))
394- then {
395- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
396- if ((period == period))
397- then {
398- let userBaseAssetAmountToConvert = valueOrElse(getInteger(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress)), 0)
399- let checkAmountToConvert = if ((userBaseAssetAmountToConvert > 0))
400- then true
401- else throwErr("nothing to claim")
402- if ((checkAmountToConvert == checkAmountToConvert))
403- then {
404- let userBaseAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period"))
405- let checkPeriod = if ((period > userBaseAssetAmountToConvertPeriod))
406- then true
407- else throwErr("invalid period")
408- if ((checkPeriod == checkPeriod))
409- then {
410- let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodPut(baseAssetId, userBaseAssetAmountToConvertPeriod)), wrapErr("failed to get price")))
411- let shareAssetAmount = toInt(fraction(toBigInt(userBaseAssetAmountToConvert), scale18BigInt, price))
412- $Tuple2([IntegerEntry(keyUserBaseAssetAmountToConvert(baseAssetId, userAddress), 0), DeleteEntry(keyUserBaseAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, shareAssetAmount, shareAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimShareAsset", period, userAddress, i.transactionId), makeString([toString(shareAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userBaseAssetAmountToConvert)], separator))], unit)
413- }
414- else throw("Strict value is not equal to itself.")
415- }
416- else throw("Strict value is not equal to itself.")
417- }
418- else throw("Strict value is not equal to itself.")
419- }
420- else throw("Strict value is not equal to itself.")
421- }
422- else throw("Strict value is not equal to itself.")
423- }
424- else throw("Strict value is not equal to itself.")
425- }
426-
427-
428-
429-@Callable(i)
430-func get () = {
431- let checks = [shutdownCheck(i)]
432- if ((checks == checks))
433- then {
434- let pmt = if ((size(i.payments) == 1))
435- then i.payments[0]
436- else throwErr("exactly 1 payment is expected")
437- let shareAssetId = pmt.assetId
438- let baseAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyBaseAssetId(shareAssetId)), wrapErr("invalid share asset id"))))
439- if ((baseAssetId == baseAssetId))
440- then {
441- let userAddress = i.caller
442- let $t01582016009 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
443- let poolAddress = $t01582016009._1
444- let lpAssetId = $t01582016009._2
445- let period = value(getInteger(keyPeriod(baseAssetId)))
446- let userShareAssetAmountToConvertPeriodOption = getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress))
447- let claimBaseAssetInvocation = if ((userShareAssetAmountToConvertPeriodOption == unit))
448- then unit
449- else {
450- let userShareAssetAmountToConvertPeriod = value(userShareAssetAmountToConvertPeriodOption)
451- if ((userShareAssetAmountToConvertPeriod == period))
452- then unit
453- else invoke(this, "claimBaseAsset", [assetIdToString(baseAssetId), toString(userAddress)], nil)
454- }
455- if ((claimBaseAssetInvocation == claimBaseAssetInvocation))
456- then {
457- let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0)
458- let userShareAssetAmountToConvert = valueOrElse(getInteger(keyUserShareAssetAmountToConvert(baseAssetId, userAddress)), 0)
459- $Tuple2([IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), (shareAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), (userShareAssetAmountToConvert + pmt.amount)), IntegerEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress), period), StringEntry(keyHistoryEntry(baseAssetId, "get", period, userAddress, i.transactionId), makeString([toString(pmt.amount), toString(lastBlock.timestamp), toString(userShareAssetAmountToConvert)], separator))], unit)
460- }
461- else throw("Strict value is not equal to itself.")
462- }
463- else throw("Strict value is not equal to itself.")
464- }
465- else throw("Strict value is not equal to itself.")
466- }
467-
468-
469-
470-@Callable(i)
471-func claimBaseAsset (baseAssetIdStr,userAddressStr) = {
472- let checks = [shutdownCheck(i)]
473- if ((checks == checks))
474- then {
475- let userAddress = if ((userAddressStr == ""))
476- then i.caller
477- else {
478- let checkCaller = mustThis(i)
479- if ((checkCaller == checkCaller))
480- then valueOrErrorMessage(addressFromString(userAddressStr), wrapErr("invalid user address"))
481- else throw("Strict value is not equal to itself.")
482- }
483- if ((userAddress == userAddress))
484- then {
485- let baseAssetId = parseAssetId(baseAssetIdStr)
486- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
487- if ((shareAssetId == shareAssetId))
488- then {
489- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
490- if ((period == period))
491- then {
492- let userShareAssetAmountToConvert = valueOrElse(getInteger(keyUserShareAssetAmountToConvert(baseAssetId, userAddress)), 0)
493- let userShareAssetAmountToConvertPeriod = valueOrErrorMessage(getInteger(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), wrapErr("failed to get period"))
494- let checkPeriod = if ((period > userShareAssetAmountToConvertPeriod))
495- then true
496- else throwErr("invalid period")
497- if ((checkPeriod == checkPeriod))
498- then {
499- let price = toBigInt(valueOrErrorMessage(getBinary(keyPricePeriodGet(baseAssetId, userShareAssetAmountToConvertPeriod)), wrapErr("failed to get price")))
500- let baseAssetAmount = toInt(fraction(toBigInt(userShareAssetAmountToConvert), price, scale18BigInt))
501- $Tuple2([IntegerEntry(keyUserShareAssetAmountToConvert(baseAssetId, userAddress), 0), DeleteEntry(keyUserShareAssetAmountToConvertPeriod(baseAssetId, userAddress)), ScriptTransfer(userAddress, baseAssetAmount, baseAssetId), StringEntry(keyHistoryEntry(baseAssetId, "claimBaseAsset", period, userAddress, i.transactionId), makeString([toString(baseAssetAmount), toString(lastBlock.timestamp), toString(price), toString(userShareAssetAmountToConvertPeriod)], separator))], unit)
502- }
503- else throw("Strict value is not equal to itself.")
504- }
505- else throw("Strict value is not equal to itself.")
506- }
507- else throw("Strict value is not equal to itself.")
508- }
509- else throw("Strict value is not equal to itself.")
510- }
511- else throw("Strict value is not equal to itself.")
512- }
513-
514-
515-
516-@Callable(i)
517-func finalize (baseAssetIdStr) = {
518- let checks = [shutdownCheck(i)]
519- if ((checks == checks))
520- then {
521- let baseAssetId = parseAssetId(baseAssetIdStr)
522- let shareAssetId = value(parseAssetId(valueOrErrorMessage(getString(keyShareAssetId(baseAssetId)), wrapErr("invalid base asset id"))))
523- if ((shareAssetId == shareAssetId))
524- then {
525- let shareAssetInfo = valueOrErrorMessage(assetInfo(shareAssetId), wrapErr("invalid share asset id"))
526- let period = valueOrErrorMessage(getInteger(keyPeriod(baseAssetId)), wrapErr("invalid period"))
527- if ((period == period))
528- then {
529- let periodStartHeightOption = getInteger(keyPeriodStartHeight(baseAssetId, period))
530- let checkDelay = if ((periodStartHeightOption == unit))
531- then unit
532- else {
533- let delay = (height - value(periodStartHeightOption))
534- let blocksToWait = max([0, (minDelay - delay)])
535- if ((blocksToWait == 0))
536- then unit
537- else throwErr(makeString(["finalization will be possible in ", toString(blocksToWait), " blocks"], ""))
538- }
539- if ((checkDelay == checkDelay))
540- then {
541- let $t02111321294 = valueOrErrorMessage(getPoolInfo(baseAssetId), wrapErr("invalid asset"))
542- let poolAddress = $t02111321294._1
543- let lpAssetId = $t02111321294._2
544- let stakingReward = valueOrErrorMessage({
545- let @ = invoke(stakingContract, "claimWxDoNotThrow", [assetIdToString(lpAssetId)], nil)
546- if ($isInstanceOf(@, "Int"))
547- then @
548- else unit
549- }, wrapErr("invalid claimWx result"))
550- if ((stakingReward == stakingReward))
551- then {
552- let baseAssetAmountToConvert = valueOrElse(getInteger(keyBaseAssetAmountToConvert(baseAssetId)), 0)
553- let shareAssetAmountToConvert = valueOrElse(getInteger(keyShareAssetAmountToConvert(baseAssetId)), 0)
554- let checkFinalizationIsRequired = {
555- let isFinalizationRequired = if (if ((stakingReward > 0))
556- then true
557- else (baseAssetAmountToConvert > 0))
558- then true
559- else (shareAssetAmountToConvert > 0)
560- if (isFinalizationRequired)
561- then true
562- else throwErr("nothing to finalize")
563- }
564- if ((checkFinalizationIsRequired == checkFinalizationIsRequired))
565- then {
566- let useStakingReward = if ((stakingReward > 0))
567- then {
568- let lockPart = fraction(stakingReward, lockFraction, lockFractionMultiplier)
569- let convertPart = (stakingReward - lockPart)
570- let r = invoke(boostingContract, "userMaxDurationREADONLY", [toString(this)], nil)
571- let lock = if ((lockPart > 0))
572- then match r {
573- case _ =>
574- if (if (if ($isInstanceOf($match0._1, "String"))
575- then $isInstanceOf($match0._2, "Int")
576- else false)
577- then $isInstanceOf($match0, "(String, Int)")
578- else false)
579- then {
580- let function = $match0._1
581- let duration = $match0._2
582- if ((lockPart > 0))
583- then invoke(boostingContract, function, [duration], [AttachedPayment(wxAssetId, lockPart)])
584- else unit
585- }
586- else throwErr("invalid lock params")
587- }
588- else unit
589- if ((lock == lock))
590- then {
591- let convertedAmount = if ((convertPart > 0))
592- then {
593- let inAssetId = wxAssetId
594- let minimumToReceive = 0
595- let outAssetIdStr = assetIdToString(usdtAssetId)
596- let targetAddress = toString(this)
597- valueOrErrorMessage({
598- let @ = invoke(swapContract, "swap", [minimumToReceive, outAssetIdStr, targetAddress], [AttachedPayment(inAssetId, convertPart)])
599- if ($isInstanceOf(@, "Int"))
600- then @
601- else unit
602- }, wrapErr("invalid swap result"))
603- }
604- else 0
605- if ((convertedAmount == convertedAmount))
606- then {
607- let lpAssetAmount = if ((convertedAmount > 0))
608- then {
609- let minOutAmount = 0
610- let autoStake = true
611- valueOrErrorMessage({
612- let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(usdtAssetId, convertedAmount)])
613- if ($isInstanceOf(@, "Int"))
614- then @
615- else unit
616- }, wrapErr("invalid putOneTknV2 result"))
617- }
618- else 0
619- if ((lpAssetAmount == lpAssetAmount))
620- then lpAssetAmount
621- else throw("Strict value is not equal to itself.")
622- }
623- else throw("Strict value is not equal to itself.")
624- }
625- else throw("Strict value is not equal to itself.")
626- }
627- else unit
628- if ((useStakingReward == useStakingReward))
629- then {
630- let getActions = if ((shareAssetAmountToConvert > 0))
631- then {
632- let price = calcPrice(lpAssetId, shareAssetId)
633- if ((price == price))
634- then {
635- let unstakeAmount = toInt(fraction(toBigInt(shareAssetAmountToConvert), price, scale18BigInt, FLOOR))
636- let baseAssetAmount = {
637- let outAssetId = baseAssetId
638- let minOutAmount = 0
639- valueOrErrorMessage({
640- let @ = invoke(poolAddress, "unstakeAndGetOneTknV2", [unstakeAmount, assetIdToString(outAssetId), minOutAmount], nil)
641- if ($isInstanceOf(@, "Int"))
642- then @
643- else unit
644- }, wrapErr("invalid unstakeAndGetOneTknV2 result"))
645- }
646- if ((baseAssetAmount == baseAssetAmount))
647- then {
648- let shareAssetBurn = if ((shareAssetInfo.issuer == this))
649- then invoke(this, "burn", [shareAssetId, shareAssetAmountToConvert], nil)
650- else throwErr("invalid share asset issuer")
651- if ((shareAssetBurn == shareAssetBurn))
652- then {
653- let priceGet = fraction(toBigInt(baseAssetAmount), scale18BigInt, toBigInt(shareAssetAmountToConvert), FLOOR)
654- let priceGetUpdateActions = [BinaryEntry(keyPricePeriodGet(baseAssetId, period), toBytes(priceGet)), StringEntry(keyPriceGetHistory(baseAssetId), toString(priceGet))]
655- priceGetUpdateActions
656- }
657- else throw("Strict value is not equal to itself.")
658- }
659- else throw("Strict value is not equal to itself.")
660- }
661- else throw("Strict value is not equal to itself.")
662- }
663- else nil
664- if ((getActions == getActions))
665- then {
666- let putActions = if ((baseAssetAmountToConvert > 0))
667- then {
668- let lpAssetAmount = {
669- let minOutAmount = 0
670- let autoStake = true
671- valueOrErrorMessage({
672- let @ = invoke(poolAddress, "putOneTknV2", [minOutAmount, autoStake], [AttachedPayment(baseAssetId, baseAssetAmountToConvert)])
673- if ($isInstanceOf(@, "Int"))
674- then @
675- else unit
676- }, wrapErr("invalid putOneTknV2 result"))
677- }
678- if ((lpAssetAmount == lpAssetAmount))
679- then {
680- let price = calcPrice(lpAssetId, shareAssetId)
681- if ((price == price))
682- then {
683- let checkPrice = if ((value(toInt(price)) != 0))
684- then true
685- else throw("price is ZERO")
686- if ((checkPrice == checkPrice))
687- then {
688- let shareAssetAmount = toInt(fraction(toBigInt(lpAssetAmount), scale18BigInt, price, FLOOR))
689- let checkShareAssetAmount = if ((value(toInt(price)) != 0))
690- then true
691- else throw("shareAssetAmount is ZERO")
692- if ((checkShareAssetAmount == checkShareAssetAmount))
693- then {
694- let shareAssetReissue = if ((shareAssetInfo.issuer == this))
695- then invoke(this, "emit", [shareAssetId, shareAssetAmount], nil)
696- else throwErr("invalid share asset issuer")
697- if ((shareAssetReissue == shareAssetReissue))
698- then {
699- let pricePut = fraction(toBigInt(baseAssetAmountToConvert), scale18BigInt, toBigInt(shareAssetAmount))
700- let pricePutUpdateActions = [BinaryEntry(keyPricePeriodPut(baseAssetId, period), toBytes(pricePut)), StringEntry(keyPricePutHistory(baseAssetId), toString(pricePut))]
701- pricePutUpdateActions
702- }
703- else throw("Strict value is not equal to itself.")
704- }
705- else throw("Strict value is not equal to itself.")
706- }
707- else throw("Strict value is not equal to itself.")
708- }
709- else throw("Strict value is not equal to itself.")
710- }
711- else throw("Strict value is not equal to itself.")
712- }
713- else nil
714- if ((putActions == putActions))
715- then {
716- let newPeriod = (period + 1)
717- let lastPrice = calcPrice(lpAssetId, shareAssetId)
718- let actions = (([IntegerEntry(keyPeriod(baseAssetId), newPeriod), IntegerEntry(keyPeriodStartHeight(baseAssetId, newPeriod), height), IntegerEntry(keyShareAssetAmountToConvert(baseAssetId), 0), IntegerEntry(keyBaseAssetAmountToConvert(baseAssetId), 0), BinaryEntry(keyPricePeriod(baseAssetId, period), toBytes(lastPrice)), StringEntry(keyPriceHistory(baseAssetId), toString(lastPrice))] ++ putActions) ++ getActions)
719- $Tuple2(actions, toBytes(lastPrice))
720- }
721- else throw("Strict value is not equal to itself.")
722- }
723- else throw("Strict value is not equal to itself.")
724- }
725- else throw("Strict value is not equal to itself.")
726- }
727- else throw("Strict value is not equal to itself.")
728- }
729- else throw("Strict value is not equal to itself.")
730- }
731- else throw("Strict value is not equal to itself.")
732- }
733- else throw("Strict value is not equal to itself.")
734- }
735246 else throw("Strict value is not equal to itself.")
736247 }
737248 else throw("Strict value is not equal to itself.")
738249 }
739250
740251
741252 @Verifier(tx)
742253 func verify () = {
743254 let targetPublicKey = match managerPublicKeyOrUnit() {
744255 case pk: ByteVector =>
745256 pk
746257 case _: Unit =>
747258 tx.senderPublicKey
748259 case _ =>
749260 throw("Match error")
750261 }
751262 sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey)
752263 }
753264

github/deemru/w8io/026f985 
64.45 ms