tx · 3h61i52da33peAjoDhbkS8BsCcWZQPe9du5hU69rqSKu

3MvkaAmaBu7ngK68fQMV8faYLdcnnBJtrj5:  -0.01400000 Waves

2021.12.14 18:07 [1834085] smart account 3MvkaAmaBu7ngK68fQMV8faYLdcnnBJtrj5 > SELF 0.00000000 Waves

{ "type": 13, "id": "3h61i52da33peAjoDhbkS8BsCcWZQPe9du5hU69rqSKu", "fee": 1400000, "feeAssetId": null, "timestamp": 1639494503894, "version": 1, "sender": "3MvkaAmaBu7ngK68fQMV8faYLdcnnBJtrj5", "senderPublicKey": "hXnMcUKtqomxgSbnHn7eToAsYJGaa1PWq7Lq6QQLumm", "proofs": [ "2LPtmVRgQuUs4cygaYM6e46yvC6dKsWtteSUhHX3Brsn2U7HHbYgVLT349De9GdEaUkzhUfTjExoZFfGCCNddJnx" ], "script": "base64:AAIFAAAAAAAAABoIAhIDCgEIEgASBAoCCAESAwoBCBIECgIICAAAAAwAAAAAA1NFUAIAAAACX18BAAAAD2dldFN0cmluZ09yRmFpbAAAAAEAAAADa2V5CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQiAAAAAQUAAAADa2V5CQABLAAAAAIJAAEsAAAAAgIAAAAPbWFuZGF0b3J5IHRoaXMuBQAAAANrZXkCAAAADyBpcyBub3QgZGVmaW5lZAEAAAAYZ2V0U3RyaW5nQnlBZGRyZXNzT3JGYWlsAAAAAgAAAAdhZGRyZXNzAAAAA2tleQkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEHQAAAAIFAAAAB2FkZHJlc3MFAAAAA2tleQkAASwAAAACCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAptYW5kYXRvcnkgCQAEJQAAAAEFAAAAB2FkZHJlc3MCAAAAAS4FAAAAA2tleQIAAAAPIGlzIG5vdCBkZWZpbmVkAQAAABFrZXlGYWN0b3J5QWRkcmVzcwAAAAACAAAAHCVzJXNfX2NvbmZpZ19fZmFjdG9yeUFkZHJlc3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AAAAgkABEwAAAACAgAAAAYlcyVzJWQJAARMAAAAAgUAAAAMbHBBc3NldElkU3RyCQAETAAAAAIFAAAAC3VzZXJBZGRyZXNzCQAETAAAAAICAAAAATAFAAAAA25pbAUAAAADU0VQAAAAADz8MV0=", "chainId": 84, "height": 1834085, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6pEJp49btvb7sddDa9SwvejMnwHYfqh8uFfsUTQ1P67W Next: 3FeqZfcBUkgvS4hWunrgSPa5komepakdZsdsYAiZkQe2 Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let SCALE8 = 8
5-
6-let MULT8 = 100000000
7-
8-let SCALE18 = 18
9-
10-let MULT18 = toBigInt(1000000000000000000)
11-
124 let SEP = "__"
135
146 func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined"))
179 func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined"))
1810
1911
20-func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
21-
22-
23-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined"))
24-
25-
2612 func keyFactoryAddress () = "%s%s__config__factoryAddress"
27-
28-
29-let IdxFactoryCfgStakingDapp = 1
30-
31-let IdxFactoryCfgBoostingDapp = 2
32-
33-let IdxFactoryCfgIdoDapp = 3
34-
35-let IdxFactoryCfgTeamDapp = 4
36-
37-let IdxFactoryCfgEmissionDapp = 5
38-
39-let IdxFactoryCfgRestDapp = 6
40-
41-let IdxFactoryCfgSlippageDapp = 7
42-
43-func keyFactoryCfg () = "%s__factoryConfig"
4413
4514
4615 func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP)
4716
4817
49-func keyFactoryLpList () = "%s__lpTokensList"
50-
51-
52-func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP)
53-
54-
55-func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP)
56-
57-
5818 func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress()))
59-
60-
61-func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP)
62-
63-
64-func readFactoryCfgOrFail (factory) = split(getStringByAddressOrFail(factory, keyFactoryCfg()), SEP)
65-
66-
67-func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp])
68-
69-
70-func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp])
71-
72-
73-func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp])
74-
75-
76-func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current"
77-
78-
79-func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current"
80-
81-
82-func keyEmissionStartBlock () = "%s%s__emission__startBlock"
83-
84-
85-func keyEmissionDurationInBlocks () = "%s%s__emission__duration"
86-
87-
88-func keyEmissionEndBlock () = "%s%s__emission__endBlock"
8919
9020
9121 func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP)
14171 @Callable(i)
14272 func unstake (lpAssetIdStr,amount) = {
14373 let factory = readFactoryAddressOrFail()
144- let userAddressStr = toString(i.caller)
14574 let lpAssetId = fromBase58String(lpAssetIdStr)
146- if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)))))
147- then throw(("unsupported lp asset " + lpAssetIdStr))
148- else {
149- let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr)
150- let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
151- let stakedByUser = readStaked(stakedByUserKEY)
152- let stakedTotal = readStaked(stakedTotalKEY)
153- if ((amount > stakedByUser))
154- then throw("passed amount is less then available")
155- else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)]
156- }
75+ let lpDappStr = valueOrErrorMessage(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr))
76+ let callerStr = toString(i.caller)
77+ let userAddressStr = if ((callerStr == lpDappStr))
78+ then toString(i.originCaller)
79+ else callerStr
80+ let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr)
81+ let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
82+ let stakedByUser = readStaked(stakedByUserKEY)
83+ let stakedTotal = readStaked(stakedTotalKEY)
84+ if ((amount > stakedByUser))
85+ then throw("passed amount is less then available")
86+ else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)]
15787 }
15888
15989
16494
16595
16696 @Callable(i)
167-func claimWxREADONLY (lpAssetIdStr,userAddress) = {
168- let factoryContract = readFactoryAddressOrFail()
169- let factoryCfg = readFactoryCfgOrFail(factoryContract)
170- let emissionContract = getEmissionAddressOrFail(factoryCfg)
171- let stakedByUserKEY = keyStakedByUser(userAddress, lpAssetIdStr)
172- let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
173- let stakedByUser = readStaked(stakedByUserKEY)
174- let stakedTotal = readStaked(stakedTotalKEY)
175- let poolAddressStr = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr))
176- let poolWeightMult = MULT8
177- let poolWeight = getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr))
178- let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent())
179- let emissionStartBlock = getIntOrFail(emissionContract, keyEmissionStartBlock())
180- let passedBlocks = if ((emissionStartBlock > height))
181- then 0
182- else (height - emissionStartBlock)
183- let poolWxEmission = fraction((wxEmissionPerBlock * passedBlocks), poolWeight, poolWeightMult)
184- let userWxReward = fraction(poolWxEmission, stakedByUser, stakedTotal)
185- $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, toString(userWxReward)], SEP))
186- }
97+func claimWxREADONLY (lpAssetIdStr,userAddress) = $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, "0"], SEP))
18798
18899
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let SCALE8 = 8
5-
6-let MULT8 = 100000000
7-
8-let SCALE18 = 18
9-
10-let MULT18 = toBigInt(1000000000000000000)
11-
124 let SEP = "__"
135
146 func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined"))
157
168
179 func getStringByAddressOrFail (address,key) = valueOrErrorMessage(getString(address, key), (((("mandatory " + toString(address)) + ".") + key) + " is not defined"))
1810
1911
20-func getIntOrZero (address,key) = valueOrElse(getInteger(address, key), 0)
21-
22-
23-func getIntOrFail (address,key) = valueOrErrorMessage(getInteger(address, key), (("mandatory this." + key) + " is not defined"))
24-
25-
2612 func keyFactoryAddress () = "%s%s__config__factoryAddress"
27-
28-
29-let IdxFactoryCfgStakingDapp = 1
30-
31-let IdxFactoryCfgBoostingDapp = 2
32-
33-let IdxFactoryCfgIdoDapp = 3
34-
35-let IdxFactoryCfgTeamDapp = 4
36-
37-let IdxFactoryCfgEmissionDapp = 5
38-
39-let IdxFactoryCfgRestDapp = 6
40-
41-let IdxFactoryCfgSlippageDapp = 7
42-
43-func keyFactoryCfg () = "%s__factoryConfig"
4413
4514
4615 func keyFactoryLp2AssetsMapping (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP)
4716
4817
49-func keyFactoryLpList () = "%s__lpTokensList"
50-
51-
52-func keyFactoryLpAssetToPoolContractAddress (lpAssetStr) = makeString(["%s%s%s", lpAssetStr, "mappings__lpAsset2PoolContract"], SEP)
53-
54-
55-func keyFactoryPoolWeight (contractAddress) = makeString(["%s%s", "poolWeight", contractAddress], SEP)
56-
57-
5818 func readFactoryAddressOrFail () = addressFromStringValue(getStringOrFail(keyFactoryAddress()))
59-
60-
61-func readLpList () = split(valueOrElse(getString(readFactoryAddressOrFail(), keyFactoryLpList()), ""), SEP)
62-
63-
64-func readFactoryCfgOrFail (factory) = split(getStringByAddressOrFail(factory, keyFactoryCfg()), SEP)
65-
66-
67-func getBoostingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgBoostingDapp])
68-
69-
70-func getEmissionAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgEmissionDapp])
71-
72-
73-func getStakingAddressOrFail (factoryCfg) = addressFromStringValue(factoryCfg[IdxFactoryCfgStakingDapp])
74-
75-
76-func keyEmissionRatePerBlockCurrent () = "%s%s__ratePerBlock__current"
77-
78-
79-func keyEmissionRatePerBlockMaxCurrent () = "%s%s__ratePerBlockMax__current"
80-
81-
82-func keyEmissionStartBlock () = "%s%s__emission__startBlock"
83-
84-
85-func keyEmissionDurationInBlocks () = "%s%s__emission__duration"
86-
87-
88-func keyEmissionEndBlock () = "%s%s__emission__endBlock"
8919
9020
9121 func keyStakedByUser (userAddressStr,lpAssetIdStr) = makeString(["%s%s%s__staked", userAddressStr, lpAssetIdStr], SEP)
9222
9323
9424 func keyStakedTotal (lpAssetIdStr) = ("%s%s%s__staked__total__" + lpAssetIdStr)
9525
9626
9727 func readStaked (key) = valueOrElse(getInteger(this, key), 0)
9828
9929
10030 func keyOperationHistoryRecord (type,userAddress,txId58) = makeString(["%s%s%s%s__history", type, userAddress, txId58], SEP)
10131
10232
10333 func formatHistoryRecord (userAddress,lpAssetId,type,amount) = makeString(["%s%s%s%d%d%d", userAddress, lpAssetId, type, toString(height), toString(lastBlock.timestamp), toString(amount)], SEP)
10434
10535
10636 func OperationHistoryEntry (type,userAddress,lpAssetId,amount,txId) = StringEntry(keyOperationHistoryRecord(type, userAddress, toBase58String(txId)), formatHistoryRecord(userAddress, lpAssetId, type, amount))
10737
10838
10939 @Callable(i)
11040 func constructor (factoryAddressStr) = if ((i.caller != this))
11141 then throw("not authorized")
11242 else [StringEntry(keyFactoryAddress(), factoryAddressStr)]
11343
11444
11545
11646 @Callable(i)
11747 func stake () = {
11848 let factory = readFactoryAddressOrFail()
11949 if ((size(i.payments) != 1))
12050 then throw("invalid payment - exact one payment must be attached")
12151 else {
12252 let pmt = i.payments[0]
12353 let lpAssetId = value(pmt.assetId)
12454 let lpAssetIdStr = toBase58String(lpAssetId)
12555 let amount = pmt.amount
12656 let lpDappStr = valueOrErrorMessage(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr))
12757 let callerStr = toString(i.caller)
12858 let userAddressStr = if ((callerStr == lpDappStr))
12959 then toString(i.originCaller)
13060 else callerStr
13161 let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr)
13262 let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
13363 let stakedByUser = readStaked(stakedByUserKEY)
13464 let stakedTotal = readStaked(stakedTotalKEY)
13565 [IntegerEntry(stakedByUserKEY, (stakedByUser + amount)), IntegerEntry(stakedTotalKEY, (stakedTotal + amount)), OperationHistoryEntry("stake", userAddressStr, lpAssetIdStr, amount, i.transactionId)]
13666 }
13767 }
13868
13969
14070
14171 @Callable(i)
14272 func unstake (lpAssetIdStr,amount) = {
14373 let factory = readFactoryAddressOrFail()
144- let userAddressStr = toString(i.caller)
14574 let lpAssetId = fromBase58String(lpAssetIdStr)
146- if (!(isDefined(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)))))
147- then throw(("unsupported lp asset " + lpAssetIdStr))
148- else {
149- let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr)
150- let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
151- let stakedByUser = readStaked(stakedByUserKEY)
152- let stakedTotal = readStaked(stakedTotalKEY)
153- if ((amount > stakedByUser))
154- then throw("passed amount is less then available")
155- else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)]
156- }
75+ let lpDappStr = valueOrErrorMessage(getString(factory, keyFactoryLp2AssetsMapping(lpAssetIdStr)), ("unsupported lp asset " + lpAssetIdStr))
76+ let callerStr = toString(i.caller)
77+ let userAddressStr = if ((callerStr == lpDappStr))
78+ then toString(i.originCaller)
79+ else callerStr
80+ let stakedByUserKEY = keyStakedByUser(userAddressStr, lpAssetIdStr)
81+ let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
82+ let stakedByUser = readStaked(stakedByUserKEY)
83+ let stakedTotal = readStaked(stakedTotalKEY)
84+ if ((amount > stakedByUser))
85+ then throw("passed amount is less then available")
86+ else [IntegerEntry(stakedByUserKEY, (stakedByUser - amount)), IntegerEntry(stakedTotalKEY, (stakedTotal - amount)), ScriptTransfer(i.caller, amount, lpAssetId), OperationHistoryEntry("unstake", userAddressStr, lpAssetIdStr, amount, i.transactionId)]
15787 }
15888
15989
16090
16191 @Callable(i)
16292 func claimWx (lpAssetIdStr) = throw("temorary disabled")
16393
16494
16595
16696 @Callable(i)
167-func claimWxREADONLY (lpAssetIdStr,userAddress) = {
168- let factoryContract = readFactoryAddressOrFail()
169- let factoryCfg = readFactoryCfgOrFail(factoryContract)
170- let emissionContract = getEmissionAddressOrFail(factoryCfg)
171- let stakedByUserKEY = keyStakedByUser(userAddress, lpAssetIdStr)
172- let stakedTotalKEY = keyStakedTotal(lpAssetIdStr)
173- let stakedByUser = readStaked(stakedByUserKEY)
174- let stakedTotal = readStaked(stakedTotalKEY)
175- let poolAddressStr = getStringByAddressOrFail(factoryContract, keyFactoryLpAssetToPoolContractAddress(lpAssetIdStr))
176- let poolWeightMult = MULT8
177- let poolWeight = getIntegerValue(factoryContract, keyFactoryPoolWeight(poolAddressStr))
178- let wxEmissionPerBlock = getIntOrFail(emissionContract, keyEmissionRatePerBlockCurrent())
179- let emissionStartBlock = getIntOrFail(emissionContract, keyEmissionStartBlock())
180- let passedBlocks = if ((emissionStartBlock > height))
181- then 0
182- else (height - emissionStartBlock)
183- let poolWxEmission = fraction((wxEmissionPerBlock * passedBlocks), poolWeight, poolWeightMult)
184- let userWxReward = fraction(poolWxEmission, stakedByUser, stakedTotal)
185- $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, toString(userWxReward)], SEP))
186- }
97+func claimWxREADONLY (lpAssetIdStr,userAddress) = $Tuple2(nil, makeString(["%s%s%d", lpAssetIdStr, userAddress, "0"], SEP))
18798
18899

github/deemru/w8io/fabc49c 
42.58 ms