tx · BUAPPmMevoNGeFhRBWkjKFx9ZU5y6rokVVQBzsphC8zY

3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S:  -0.01400000 Waves

2021.04.03 22:27 [1466681] smart account 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S > SELF 0.00000000 Waves

{ "type": 13, "id": "BUAPPmMevoNGeFhRBWkjKFx9ZU5y6rokVVQBzsphC8zY", "fee": 1400000, "feeAssetId": null, "timestamp": 1617478042360, "version": 2, "chainId": 84, "sender": "3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S", "senderPublicKey": "CgByewRUvLk7UtWSfRMLSYw4Ap2wT5dcdVYKideqDp9M", "proofs": [ "441iukhNArr2i4GebK9YcErh33gikYYKx4q5YdWGHHKy6ySS9ZCbRpUuQWDxhQaVotBrsVfLUo4kZGer8ExMfdjX" ], "script": "base64:AAIEAAAAAAAAAAsIAhIAEgMKAQESAAAAABYAAAAAEnVzZG5EeXpBQmFsYW5jZUtleQIAAAAYdXNkbl9keXpfYV9hc3NldF9iYWxhbmNlAAAAABJ1c2RuRHl6QkJhbGFuY2VLZXkCAAAAGHVzZG5fZHl6X2JfYXNzZXRfYmFsYW5jZQAAAAARZXRoRHl6QUJhbGFuY2VLZXkCAAAAF2V0aF9keXpfYV9hc3NldF9iYWxhbmNlAAAAABFldGhEeXpCQmFsYW5jZUtleQIAAAAXZXRoX2R5el9iX2Fzc2V0X2JhbGFuY2UAAAAAFnVzZG5EeXpQYWlySXNBY3RpdmVLZXkCAAAAEnVzZG5fZHl6X2lzX2FjdGl2ZQAAAAAVZXRoRHl6UGFpcklzQWN0aXZlS2V5AgAAABFldGhfZHl6X2lzX2FjdGl2ZQAAAAAGZmVlS2V5AgAAAANmZWUAAAAADnRvdGFsRmVlRXRoS2V5AgAAAA10b3RhbF9mZWVfZXRoAAAAAA50b3RhbEZlZVVzZEtleQIAAAANdG90YWxfZmVlX3VzZAAAAAASdG90YWxGZWVEeXpyYXB0S2V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AAApwbXRBbW91bnRCCAUAAAALJHQwNTEzOTUyMTYAAAACXzEEAAAAC3BtdEFzc2V0SWRCCAUAAAALJHQwNTEzOTUyMTYAAAACXzIDCQEAAAACIT0AAAACBQAAAAtwbXRBc3NldElkQQUAAAALdXNkbkFzc2V0SWQJAAACAAAAAQIAAAAVQSBhc3NldCBpcyBub3QgYSB1c2RuAwkBAAAAAiE9AAAAAgUAAAALcG10QXNzZXRJZEIFAAAADmR5enJhcHRBc3NldElkCQAAAgAAAAECAAAAGUIgIGFzc2V0IGlzIG5vdCBhIGR5enJ1cHQEAAAACGJhbGFuY2VBCQEAAAANZ2V0SW50S2V5RGF0YQAAAAEFAAAAEnVzZG5EeXpBQmFsYW5jZUtleQQAAAAIYmFsYW5jZUIJAQAAAA1nZXRJbnRLZXlEYXRhAAAAAQUAAAASdXNkbkR5ekJCYWxhbmNlS2V5BAAAAAp0b2tlblJhdGlvCQAAawAAAAMJAABrAAAAAwUAAAAIYmFsYW5jZUEAAAAAAAX14QAFAAAACnBtdEFtb3VudEEAAAAAAAAAA+gJAABrAAAAAwUAAAAIYmFsYW5jZUIAAAAAAAX14QAFAAAACnBtdEFtb3VudEIDCQAAZgAAAAIFAAAACnRva2VuUmF0aW8FAAAACG1heFJhdGlvCQAAAgAAAAECAAAAPUluY29ycmVjdCBhc3NldHMgYW1vdW50OiBhbW91bnRzIG11c3QgaGF2ZSB0aGUgY29udHJhY3QgcmF0aW8JAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIFAAAAEnVzZG5EeXpBQmFsYW5jZUtleQkAAGQAAAACBQAAAAhiYWxhbmNlQQUAAAAKcG10QW1vdW50QQkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgUAAAASdXNkbkR5ekJCYWxhbmNlS2V5CQAAZAAAAAIFAAAACGJhbGFuY2VCBQAAAApwbXRBbW91bnRCBQAAAANuaWwAAAAATHrN5w==", "height": 1466681, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: EW5vtRH1oJBjVYp5EPEeAfr9fG6Wse63uFjyHwDPt19T Next: 737fcYC2GDneexUZCW3e5htMANTLYaZVHZEieyfHXSqW Diff:
OldNewDifferences
2020 let totalFeeUsdKey = "total_fee_usd"
2121
2222 let totalFeeDyzraptKey = "total_fee_dyzrapt"
23+
24+let maxRatio = 1000
2325
2426 let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA'
2527
9395 else if ((i.callerPublicKey != adminPublicKey))
9496 then throw("Only admin can activate pair")
9597 else {
96- let $t029753052 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
97- let pmtAmountA = $t029753052._1
98- let pmtAssetIdA = $t029753052._2
99- let $t030613138 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
100- let pmtAmountB = $t030613138._1
101- let pmtAssetIdB = $t030613138._2
98+ let $t029953072 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
99+ let pmtAmountA = $t029953072._1
100+ let pmtAssetIdA = $t029953072._2
101+ let $t030813158 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
102+ let pmtAmountB = $t030813158._1
103+ let pmtAssetIdB = $t030813158._2
102104 if ((pmtAssetIdA != usdnAssetId))
103105 then throw("A asset is not a usdn")
104106 else if ((pmtAssetIdB != dyzraptAssetId))
120122 else false)
121123 then throw("Only usdn and dyzrupt are supporting")
122124 else {
123- let $t040354131 = getUsdnDyzAmount(assetId, amount)
124- let feeAmount = $t040354131._1
125- let rAmount = $t040354131._2
126- let rAssetId = $t040354131._3
127- let newBalanceA = $t040354131._4
128- let newBalanceB = $t040354131._5
125+ let $t040554151 = getUsdnDyzAmount(assetId, amount)
126+ let feeAmount = $t040554151._1
127+ let rAmount = $t040554151._2
128+ let rAssetId = $t040554151._3
129+ let newBalanceA = $t040554151._4
130+ let newBalanceB = $t040554151._5
129131 if ((minReceive > rAmount))
130132 then throw("Calculated amount to receive is less than specified minimum")
131133 else {
144146 else if ((i.callerPublicKey != adminPublicKey))
145147 then throw("Only admin can add liquid")
146148 else {
147- let $t050335110 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
148- let pmtAmountA = $t050335110._1
149- let pmtAssetIdA = $t050335110._2
150- let $t051195196 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
151- let pmtAmountB = $t051195196._1
152- let pmtAssetIdB = $t051195196._2
149+ let $t050535130 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
150+ let pmtAmountA = $t050535130._1
151+ let pmtAssetIdA = $t050535130._2
152+ let $t051395216 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
153+ let pmtAmountB = $t051395216._1
154+ let pmtAssetIdB = $t051395216._2
153155 if ((pmtAssetIdA != usdnAssetId))
154156 then throw("A asset is not a usdn")
155157 else if ((pmtAssetIdB != dyzraptAssetId))
158160 let balanceA = getIntKeyData(usdnDyzABalanceKey)
159161 let balanceB = getIntKeyData(usdnDyzBBalanceKey)
160162 let tokenRatio = fraction(fraction(balanceA, 100000000, pmtAmountA), 1000, fraction(balanceB, 100000000, pmtAmountB))
161- throw(toString(tokenRatio))
163+ if ((tokenRatio > maxRatio))
164+ then throw("Incorrect assets amount: amounts must have the contract ratio")
165+ else [IntegerEntry(usdnDyzABalanceKey, (balanceA + pmtAmountA)), IntegerEntry(usdnDyzBBalanceKey, (balanceB + pmtAmountB))]
162166 }
163167 }
164168
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let usdnDyzABalanceKey = "usdn_dyz_a_asset_balance"
55
66 let usdnDyzBBalanceKey = "usdn_dyz_b_asset_balance"
77
88 let ethDyzABalanceKey = "eth_dyz_a_asset_balance"
99
1010 let ethDyzBBalanceKey = "eth_dyz_b_asset_balance"
1111
1212 let usdnDyzPairIsActiveKey = "usdn_dyz_is_active"
1313
1414 let ethDyzPairIsActiveKey = "eth_dyz_is_active"
1515
1616 let feeKey = "fee"
1717
1818 let totalFeeEthKey = "total_fee_eth"
1919
2020 let totalFeeUsdKey = "total_fee_usd"
2121
2222 let totalFeeDyzraptKey = "total_fee_dyzrapt"
23+
24+let maxRatio = 1000
2325
2426 let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA'
2527
2628 let ethAssetId = base58'3JJkzB4pFXcqdJvC9TcV8ys1FLgesr5SxbhmykkpceQp'
2729
2830 let usdnAssetId = base58'9Nf5wpj6jds3VRZKDryp6Dtf3R9d8MdbjNhencLogCr5'
2931
3032 let adminPublicKey = base58'7zDUSbBXZtec3E333b1fC2wR2MPrnzh69ZrH3rwpQj9S'
3133
3234 let feeAddress = Address(base58'3N7G2kVtBTh94aEnDHQ9dpi4EdsDxAiDXjB')
3335
3436 func getIntKeyDataOrError (key) = {
3537 let v = valueOrErrorMessage(getInteger(this, key), "unable to read key")
3638 v
3739 }
3840
3941
4042 func getIntKeyData (key) = {
4143 let v = valueOrElse(getInteger(this, key), 0)
4244 v
4345 }
4446
4547
4648 func getTotalFeeByKey (key) = getIntKeyData(key)
4749
4850
4951 func getFeeAmount (amount) = {
5052 let fee = getIntKeyDataOrError(feeKey)
5153 let feeAmount = fraction(amount, fee, 10000)
5254 feeAmount
5355 }
5456
5557
5658 func getFeeKeyByAssetId (assetId) = if ((assetId == usdnAssetId))
5759 then totalFeeUsdKey
5860 else if ((assetId == ethAssetId))
5961 then totalFeeEthKey
6062 else if ((assetId == dyzraptAssetId))
6163 then totalFeeDyzraptKey
6264 else throw("Incorrect asset attached")
6365
6466
6567 func getUsdnDyzAmount (assetId,amount) = {
6668 let feeAmount = getFeeAmount(amount)
6769 let amountWithoutFee = (amount - feeAmount)
6870 let balanceA = getIntegerValue(this, usdnDyzABalanceKey)
6971 let balanceB = getIntegerValue(this, usdnDyzBBalanceKey)
7072 if ((assetId == usdnAssetId))
7173 then {
7274 let rAmount = fraction(balanceB, amountWithoutFee, (amountWithoutFee + balanceA))
7375 let rAssetId = dyzraptAssetId
7476 let newBalanceA = (amountWithoutFee + balanceA)
7577 let newBalanceB = (balanceB - rAmount)
7678 $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB)
7779 }
7880 else if ((assetId == dyzraptAssetId))
7981 then {
8082 let rAmount = fraction(balanceA, amountWithoutFee, (amountWithoutFee + balanceB))
8183 let rAssetId = usdnAssetId
8284 let newBalanceA = (balanceA - rAmount)
8385 let newBalanceB = (balanceB + amountWithoutFee)
8486 $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB)
8587 }
8688 else throw("Incorrect asset attached")
8789 }
8890
8991
9092 @Callable(i)
9193 func initUsdnDyzPair () = if (isDefined(getBoolean(this, usdnDyzPairIsActiveKey)))
9294 then throw("Pair is already active")
9395 else if ((i.callerPublicKey != adminPublicKey))
9496 then throw("Only admin can activate pair")
9597 else {
96- let $t029753052 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
97- let pmtAmountA = $t029753052._1
98- let pmtAssetIdA = $t029753052._2
99- let $t030613138 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
100- let pmtAmountB = $t030613138._1
101- let pmtAssetIdB = $t030613138._2
98+ let $t029953072 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
99+ let pmtAmountA = $t029953072._1
100+ let pmtAssetIdA = $t029953072._2
101+ let $t030813158 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
102+ let pmtAmountB = $t030813158._1
103+ let pmtAssetIdB = $t030813158._2
102104 if ((pmtAssetIdA != usdnAssetId))
103105 then throw("A asset is not a usdn")
104106 else if ((pmtAssetIdB != dyzraptAssetId))
105107 then throw("B asset is not a dyzrupt")
106108 else [BooleanEntry(usdnDyzPairIsActiveKey, true), IntegerEntry(usdnDyzABalanceKey, pmtAmountA), IntegerEntry(usdnDyzBBalanceKey, pmtAmountB), IntegerEntry(feeKey, 300)]
107109 }
108110
109111
110112
111113 @Callable(i)
112114 func exchangeUsdnDyz (minReceive) = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
113115 then throw("Pair is not active")
114116 else {
115117 let pmt = value(i.payments[0])
116118 let assetId = pmt.assetId
117119 let amount = pmt.amount
118120 if (if ((assetId != usdnAssetId))
119121 then (assetId != dyzraptAssetId)
120122 else false)
121123 then throw("Only usdn and dyzrupt are supporting")
122124 else {
123- let $t040354131 = getUsdnDyzAmount(assetId, amount)
124- let feeAmount = $t040354131._1
125- let rAmount = $t040354131._2
126- let rAssetId = $t040354131._3
127- let newBalanceA = $t040354131._4
128- let newBalanceB = $t040354131._5
125+ let $t040554151 = getUsdnDyzAmount(assetId, amount)
126+ let feeAmount = $t040554151._1
127+ let rAmount = $t040554151._2
128+ let rAssetId = $t040554151._3
129+ let newBalanceA = $t040554151._4
130+ let newBalanceB = $t040554151._5
129131 if ((minReceive > rAmount))
130132 then throw("Calculated amount to receive is less than specified minimum")
131133 else {
132134 let totalFeeKey = getFeeKeyByAssetId(assetId)
133135 let totalFee = (getTotalFeeByKey(totalFeeKey) + feeAmount)
134136 [IntegerEntry(usdnDyzABalanceKey, newBalanceA), IntegerEntry(usdnDyzBBalanceKey, newBalanceB), IntegerEntry(totalFeeKey, totalFee), ScriptTransfer(feeAddress, feeAmount, assetId), ScriptTransfer(i.caller, rAmount, rAssetId)]
135137 }
136138 }
137139 }
138140
139141
140142
141143 @Callable(i)
142144 func addLiquidToUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
143145 then throw("Pair is not active")
144146 else if ((i.callerPublicKey != adminPublicKey))
145147 then throw("Only admin can add liquid")
146148 else {
147- let $t050335110 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
148- let pmtAmountA = $t050335110._1
149- let pmtAssetIdA = $t050335110._2
150- let $t051195196 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
151- let pmtAmountB = $t051195196._1
152- let pmtAssetIdB = $t051195196._2
149+ let $t050535130 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
150+ let pmtAmountA = $t050535130._1
151+ let pmtAssetIdA = $t050535130._2
152+ let $t051395216 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
153+ let pmtAmountB = $t051395216._1
154+ let pmtAssetIdB = $t051395216._2
153155 if ((pmtAssetIdA != usdnAssetId))
154156 then throw("A asset is not a usdn")
155157 else if ((pmtAssetIdB != dyzraptAssetId))
156158 then throw("B asset is not a dyzrupt")
157159 else {
158160 let balanceA = getIntKeyData(usdnDyzABalanceKey)
159161 let balanceB = getIntKeyData(usdnDyzBBalanceKey)
160162 let tokenRatio = fraction(fraction(balanceA, 100000000, pmtAmountA), 1000, fraction(balanceB, 100000000, pmtAmountB))
161- throw(toString(tokenRatio))
163+ if ((tokenRatio > maxRatio))
164+ then throw("Incorrect assets amount: amounts must have the contract ratio")
165+ else [IntegerEntry(usdnDyzABalanceKey, (balanceA + pmtAmountA)), IntegerEntry(usdnDyzBBalanceKey, (balanceB + pmtAmountB))]
162166 }
163167 }
164168
165169

github/deemru/w8io/169f3d6 
63.00 ms