tx · 2oQ3QJHoAg5mVsXyP6N3VMg76M81bCkePLi3KJ1oU9KX

3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S:  -0.01400000 Waves

2021.04.03 22:04 [1466659] smart account 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S > SELF 0.00000000 Waves

{ "type": 13, "id": "2oQ3QJHoAg5mVsXyP6N3VMg76M81bCkePLi3KJ1oU9KX", "fee": 1400000, "feeAssetId": null, "timestamp": 1617476764833, "version": 2, "chainId": 84, "sender": "3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S", "senderPublicKey": "CgByewRUvLk7UtWSfRMLSYw4Ap2wT5dcdVYKideqDp9M", "proofs": [ "2U2eDatNBrE8BcuvfDrERYMDt98BSR9PZWCf6B5Lf9kHHn4YCr5C14n6GARJz1rfnwppMvzDUPgpf9Mv2AjYm8nH" ], "script": "base64:AAIEAAAAAAAAAAsIAhIAEgMKAQESAAAAABUAAAAAEnVzZG5EeXpBQmFsYW5jZUtleQIAAAAYdXNkbl9keXpfYV9hc3NldF9iYWxhbmNlAAAAABJ1c2RuRHl6QkJhbGFuY2VLZXkCAAAAGHVzZG5fZHl6X2JfYXNzZXRfYmFsYW5jZQAAAAARZXRoRHl6QUJhbGFuY2VLZXkCAAAAF2V0aF9keXpfYV9hc3NldF9iYWxhbmNlAAAAABFldGhEeXpCQmFsYW5jZUtleQIAAAAXZXRoX2R5el9iX2Fzc2V0X2JhbGFuY2UAAAAAFnVzZG5EeXpQYWlySXNBY3RpdmVLZXkCAAAAEnVzZG5fZHl6X2lzX2FjdGl2ZQAAAAAVZXRoRHl6UGFpcklzQWN0aXZlS2V5AgAAABFldGhfZHl6X2lzX2FjdGl2ZQAAAAAGZmVlS2V5AgAAAANmZWUAAAAADnRvdGFsRmVlRXRoS2V5AgAAAA10b3RhbF9mZWVfZXRoAAAAAA50b3RhbEZlZVVzZEtleQIAAAANdG90YWxfZmVlX3VzZAAAAAASdG90YWxGZWVEeXp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tdEFtb3VudEIIBQAAAAskdDA1MTE5NTE5NgAAAAJfMQQAAAALcG10QXNzZXRJZEIIBQAAAAskdDA1MTE5NTE5NgAAAAJfMgMJAQAAAAIhPQAAAAIFAAAAC3BtdEFzc2V0SWRBBQAAAAt1c2RuQXNzZXRJZAkAAAIAAAABAgAAABVBIGFzc2V0IGlzIG5vdCBhIHVzZG4DCQEAAAACIT0AAAACBQAAAAtwbXRBc3NldElkQgUAAAAOZHl6cmFwdEFzc2V0SWQJAAACAAAAAQIAAAAZQiAgYXNzZXQgaXMgbm90IGEgZHl6cnVwdAQAAAAIYmFsYW5jZUEJAQAAAA1nZXRJbnRLZXlEYXRhAAAAAQUAAAASdXNkbkR5ekFCYWxhbmNlS2V5BAAAAAhiYWxhbmNlQgkBAAAADWdldEludEtleURhdGEAAAABBQAAABJ1c2RuRHl6QkJhbGFuY2VLZXkEAAAAC3Rva2VuUmF0aW8xCQAAawAAAAMJAABrAAAAAwUAAAAIYmFsYW5jZUEAAAAAAAX14QAFAAAACnBtdEFtb3VudEEAAAAAAAAAAAEJAABrAAAAAwUAAAAIYmFsYW5jZUIAAAAAAAX14QAFAAAACnBtdEFtb3VudEIEAAAAC3Rva2VuUmF0aW8yCQAAawAAAAMJAABrAAAAAwUAAAAIYmFsYW5jZUEAAAAAAAX14QAFAAAACnBtdEFtb3VudEEAAAAAAAAAA+gJAABrAAAAAwUAAAAIYmFsYW5jZUIAAAAAAAX14QAFAAAACnBtdEFtb3VudEIJAAACAAAAAQkAASwAAAACCQABLAAAAAIJAAGkAAAAAQUAAAALdG9rZW5SYXRpbzECAAAAASAJAAGkAAAAAQUAAAALdG9rZW5SYXRpbzIAAAAASClBFA==", "height": 1466659, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: H3Ps2DpcnSkvWMZwgPrUc7AH59fe5ZoA4KM1MTX6on4C Next: 4SY8U1pLgFKAZGVqa64guqVYx2M5oMsChvamFBFA2Pt6 Diff:
OldNewDifferences
109109
110110
111111 @Callable(i)
112-func exchangeUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
112+func exchangeUsdnDyz (minReceive) = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
113113 then throw("Pair is not active")
114114 else {
115115 let pmt = value(i.payments[0])
120120 else false)
121121 then throw("Only usdn and dyzrupt are supporting")
122122 else {
123- let $t040204116 = getUsdnDyzAmount(assetId, amount)
124- let feeAmount = $t040204116._1
125- let rAmount = $t040204116._2
126- let rAssetId = $t040204116._3
127- let newBalanceA = $t040204116._4
128- let newBalanceB = $t040204116._5
129- let totalFeeKey = getFeeKeyByAssetId(assetId)
130- let totalFee = (getTotalFeeByKey(totalFeeKey) + feeAmount)
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
129+ if ((minReceive > rAmount))
130+ then throw("Calculated amount to receive is less than specified minimum")
131+ else {
132+ let totalFeeKey = getFeeKeyByAssetId(assetId)
133+ let totalFee = (getTotalFeeByKey(totalFeeKey) + feeAmount)
131134 [IntegerEntry(usdnDyzABalanceKey, newBalanceA), IntegerEntry(usdnDyzBBalanceKey, newBalanceB), IntegerEntry(totalFeeKey, totalFee), ScriptTransfer(feeAddress, feeAmount, assetId), ScriptTransfer(i.caller, rAmount, rAssetId)]
135+ }
132136 }
133137 }
138+
139+
140+
141+@Callable(i)
142+func addLiquidToUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
143+ then throw("Pair is not active")
144+ else if ((i.callerPublicKey != adminPublicKey))
145+ then throw("Only admin can add liquid")
146+ 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
153+ if ((pmtAssetIdA != usdnAssetId))
154+ then throw("A asset is not a usdn")
155+ else if ((pmtAssetIdB != dyzraptAssetId))
156+ then throw("B asset is not a dyzrupt")
157+ else {
158+ let balanceA = getIntKeyData(usdnDyzABalanceKey)
159+ let balanceB = getIntKeyData(usdnDyzBBalanceKey)
160+ let tokenRatio1 = fraction(fraction(balanceA, 100000000, pmtAmountA), 1, fraction(balanceB, 100000000, pmtAmountB))
161+ let tokenRatio2 = fraction(fraction(balanceA, 100000000, pmtAmountA), 1000, fraction(balanceB, 100000000, pmtAmountB))
162+ throw(((toString(tokenRatio1) + " ") + toString(tokenRatio2)))
163+ }
164+ }
134165
135166
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"
2323
2424 let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA'
2525
2626 let ethAssetId = base58'3JJkzB4pFXcqdJvC9TcV8ys1FLgesr5SxbhmykkpceQp'
2727
2828 let usdnAssetId = base58'9Nf5wpj6jds3VRZKDryp6Dtf3R9d8MdbjNhencLogCr5'
2929
3030 let adminPublicKey = base58'7zDUSbBXZtec3E333b1fC2wR2MPrnzh69ZrH3rwpQj9S'
3131
3232 let feeAddress = Address(base58'3N7G2kVtBTh94aEnDHQ9dpi4EdsDxAiDXjB')
3333
3434 func getIntKeyDataOrError (key) = {
3535 let v = valueOrErrorMessage(getInteger(this, key), "unable to read key")
3636 v
3737 }
3838
3939
4040 func getIntKeyData (key) = {
4141 let v = valueOrElse(getInteger(this, key), 0)
4242 v
4343 }
4444
4545
4646 func getTotalFeeByKey (key) = getIntKeyData(key)
4747
4848
4949 func getFeeAmount (amount) = {
5050 let fee = getIntKeyDataOrError(feeKey)
5151 let feeAmount = fraction(amount, fee, 10000)
5252 feeAmount
5353 }
5454
5555
5656 func getFeeKeyByAssetId (assetId) = if ((assetId == usdnAssetId))
5757 then totalFeeUsdKey
5858 else if ((assetId == ethAssetId))
5959 then totalFeeEthKey
6060 else if ((assetId == dyzraptAssetId))
6161 then totalFeeDyzraptKey
6262 else throw("Incorrect asset attached")
6363
6464
6565 func getUsdnDyzAmount (assetId,amount) = {
6666 let feeAmount = getFeeAmount(amount)
6767 let amountWithoutFee = (amount - feeAmount)
6868 let balanceA = getIntegerValue(this, usdnDyzABalanceKey)
6969 let balanceB = getIntegerValue(this, usdnDyzBBalanceKey)
7070 if ((assetId == usdnAssetId))
7171 then {
7272 let rAmount = fraction(balanceB, amountWithoutFee, (amountWithoutFee + balanceA))
7373 let rAssetId = dyzraptAssetId
7474 let newBalanceA = (amountWithoutFee + balanceA)
7575 let newBalanceB = (balanceB - rAmount)
7676 $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB)
7777 }
7878 else if ((assetId == dyzraptAssetId))
7979 then {
8080 let rAmount = fraction(balanceA, amountWithoutFee, (amountWithoutFee + balanceB))
8181 let rAssetId = usdnAssetId
8282 let newBalanceA = (balanceA - rAmount)
8383 let newBalanceB = (balanceB + amountWithoutFee)
8484 $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB)
8585 }
8686 else throw("Incorrect asset attached")
8787 }
8888
8989
9090 @Callable(i)
9191 func initUsdnDyzPair () = if (isDefined(getBoolean(this, usdnDyzPairIsActiveKey)))
9292 then throw("Pair is already active")
9393 else if ((i.callerPublicKey != adminPublicKey))
9494 then throw("Only admin can activate pair")
9595 else {
9696 let $t029753052 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
9797 let pmtAmountA = $t029753052._1
9898 let pmtAssetIdA = $t029753052._2
9999 let $t030613138 = $Tuple2(i.payments[1].amount, i.payments[1].assetId)
100100 let pmtAmountB = $t030613138._1
101101 let pmtAssetIdB = $t030613138._2
102102 if ((pmtAssetIdA != usdnAssetId))
103103 then throw("A asset is not a usdn")
104104 else if ((pmtAssetIdB != dyzraptAssetId))
105105 then throw("B asset is not a dyzrupt")
106106 else [BooleanEntry(usdnDyzPairIsActiveKey, true), IntegerEntry(usdnDyzABalanceKey, pmtAmountA), IntegerEntry(usdnDyzBBalanceKey, pmtAmountB), IntegerEntry(feeKey, 300)]
107107 }
108108
109109
110110
111111 @Callable(i)
112-func exchangeUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
112+func exchangeUsdnDyz (minReceive) = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
113113 then throw("Pair is not active")
114114 else {
115115 let pmt = value(i.payments[0])
116116 let assetId = pmt.assetId
117117 let amount = pmt.amount
118118 if (if ((assetId != usdnAssetId))
119119 then (assetId != dyzraptAssetId)
120120 else false)
121121 then throw("Only usdn and dyzrupt are supporting")
122122 else {
123- let $t040204116 = getUsdnDyzAmount(assetId, amount)
124- let feeAmount = $t040204116._1
125- let rAmount = $t040204116._2
126- let rAssetId = $t040204116._3
127- let newBalanceA = $t040204116._4
128- let newBalanceB = $t040204116._5
129- let totalFeeKey = getFeeKeyByAssetId(assetId)
130- let totalFee = (getTotalFeeByKey(totalFeeKey) + feeAmount)
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
129+ if ((minReceive > rAmount))
130+ then throw("Calculated amount to receive is less than specified minimum")
131+ else {
132+ let totalFeeKey = getFeeKeyByAssetId(assetId)
133+ let totalFee = (getTotalFeeByKey(totalFeeKey) + feeAmount)
131134 [IntegerEntry(usdnDyzABalanceKey, newBalanceA), IntegerEntry(usdnDyzBBalanceKey, newBalanceB), IntegerEntry(totalFeeKey, totalFee), ScriptTransfer(feeAddress, feeAmount, assetId), ScriptTransfer(i.caller, rAmount, rAssetId)]
135+ }
132136 }
133137 }
138+
139+
140+
141+@Callable(i)
142+func addLiquidToUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey))))
143+ then throw("Pair is not active")
144+ else if ((i.callerPublicKey != adminPublicKey))
145+ then throw("Only admin can add liquid")
146+ 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
153+ if ((pmtAssetIdA != usdnAssetId))
154+ then throw("A asset is not a usdn")
155+ else if ((pmtAssetIdB != dyzraptAssetId))
156+ then throw("B asset is not a dyzrupt")
157+ else {
158+ let balanceA = getIntKeyData(usdnDyzABalanceKey)
159+ let balanceB = getIntKeyData(usdnDyzBBalanceKey)
160+ let tokenRatio1 = fraction(fraction(balanceA, 100000000, pmtAmountA), 1, fraction(balanceB, 100000000, pmtAmountB))
161+ let tokenRatio2 = fraction(fraction(balanceA, 100000000, pmtAmountA), 1000, fraction(balanceB, 100000000, pmtAmountB))
162+ throw(((toString(tokenRatio1) + " ") + toString(tokenRatio2)))
163+ }
164+ }
134165
135166

github/deemru/w8io/169f3d6 
32.66 ms