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:AAIEAAAAAAAAAAsIAhIAEgMKAQESAAAAABUAAAAAEnVzZG5EeXpBQmFsYW5jZUtleQIAAAAYdXNkbl9keXpfYV9hc3NldF9iYWxhbmNlAAAAABJ1c2RuRHl6QkJhbGFuY2VLZXkCAAAAGHVzZG5fZHl6X2JfYXNzZXRfYmFsYW5jZQAAAAARZXRoRHl6QUJhbGFuY2VLZXkCAAAAF2V0aF9keXpfYV9hc3NldF9iYWxhbmNlAAAAABFldGhEeXpCQmFsYW5jZUtleQIAAAAXZXRoX2R5el9iX2Fzc2V0X2JhbGFuY2UAAAAAFnVzZG5EeXpQYWlySXNBY3RpdmVLZXkCAAAAEnVzZG5fZHl6X2lzX2FjdGl2ZQAAAAAVZXRoRHl6UGFpcklzQWN0aXZlS2V5AgAAABFldGhfZHl6X2lzX2FjdGl2ZQAAAAAGZmVlS2V5AgAAAANmZWUAAAAADnRvdGFsRmVlRXRoS2V5AgAAAA10b3RhbF9mZWVfZXRoAAAAAA50b3RhbEZlZVVzZEtleQIAAAANdG90YWxfZmVlX3VzZAAAAAASdG90YWxGZWVEeXpy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dEFtb3VudEIIBQAAAAskdDA1MTE5NTE5NgAAAAJfMQQAAAALcG10QXNzZXRJZEIIBQAAAAskdDA1MTE5NTE5NgAAAAJfMgMJAQAAAAIhPQAAAAIFAAAAC3BtdEFzc2V0SWRBBQAAAAt1c2RuQXNzZXRJZAkAAAIAAAABAgAAABVBIGFzc2V0IGlzIG5vdCBhIHVzZG4DCQEAAAACIT0AAAACBQAAAAtwbXRBc3NldElkQgUAAAAOZHl6cmFwdEFzc2V0SWQJAAACAAAAAQIAAAAZQiAgYXNzZXQgaXMgbm90IGEgZHl6cnVwdAQAAAAIYmFsYW5jZUEJAQAAAA1nZXRJbnRLZXlEYXRhAAAAAQUAAAASdXNkbkR5ekFCYWxhbmNlS2V5BAAAAAhiYWxhbmNlQgkBAAAADWdldEludEtleURhdGEAAAABBQAAABJ1c2RuRHl6QkJhbGFuY2VLZXkEAAAAC3Rva2VuUmF0aW8xCQAAawAAAAMJAABrAAAAAwUAAAAIYmFsYW5jZUEAAAAAAAX14QAFAAAACnBtdEFtb3VudEEAAAAAAAAAAAEJAABrAAAAAwUAAAAIYmFsYW5jZUIAAAAAAAX14QAFAAAACnBtdEFtb3VudEIEAAAAC3Rva2VuUmF0aW8yCQAAawAAAAMJAABrAAAAAwUAAAAIYmFsYW5jZUEAAAAAAAX14QAFAAAACnBtdEFtb3VudEEAAAAAAAAAA+gJAABrAAAAAwUAAAAIYmFsYW5jZUIAAAAAAAX14QAFAAAACnBtdEFtb3VudEIJAAACAAAAAQkAASwAAAACCQABLAAAAAIJAAGkAAAAAQUAAAALdG9rZW5SYXRpbzECAAAAASAJAAGkAAAAAQUAAAALdG9rZW5SYXRpbzIAAAAASClBFA==", "height": 1466659, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: H3Ps2DpcnSkvWMZwgPrUc7AH59fe5ZoA4KM1MTX6on4C Next: 4SY8U1pLgFKAZGVqa64guqVYx2M5oMsChvamFBFA2Pt6 Diff:
Old | New | Differences | |
---|---|---|---|
109 | 109 | ||
110 | 110 | ||
111 | 111 | @Callable(i) | |
112 | - | func exchangeUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey)))) | |
112 | + | func exchangeUsdnDyz (minReceive) = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey)))) | |
113 | 113 | then throw("Pair is not active") | |
114 | 114 | else { | |
115 | 115 | let pmt = value(i.payments[0]) | |
120 | 120 | else false) | |
121 | 121 | then throw("Only usdn and dyzrupt are supporting") | |
122 | 122 | 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) | |
131 | 134 | [IntegerEntry(usdnDyzABalanceKey, newBalanceA), IntegerEntry(usdnDyzBBalanceKey, newBalanceB), IntegerEntry(totalFeeKey, totalFee), ScriptTransfer(feeAddress, feeAmount, assetId), ScriptTransfer(i.caller, rAmount, rAssetId)] | |
135 | + | } | |
132 | 136 | } | |
133 | 137 | } | |
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 | + | } | |
134 | 165 | ||
135 | 166 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let usdnDyzABalanceKey = "usdn_dyz_a_asset_balance" | |
5 | 5 | ||
6 | 6 | let usdnDyzBBalanceKey = "usdn_dyz_b_asset_balance" | |
7 | 7 | ||
8 | 8 | let ethDyzABalanceKey = "eth_dyz_a_asset_balance" | |
9 | 9 | ||
10 | 10 | let ethDyzBBalanceKey = "eth_dyz_b_asset_balance" | |
11 | 11 | ||
12 | 12 | let usdnDyzPairIsActiveKey = "usdn_dyz_is_active" | |
13 | 13 | ||
14 | 14 | let ethDyzPairIsActiveKey = "eth_dyz_is_active" | |
15 | 15 | ||
16 | 16 | let feeKey = "fee" | |
17 | 17 | ||
18 | 18 | let totalFeeEthKey = "total_fee_eth" | |
19 | 19 | ||
20 | 20 | let totalFeeUsdKey = "total_fee_usd" | |
21 | 21 | ||
22 | 22 | let totalFeeDyzraptKey = "total_fee_dyzrapt" | |
23 | 23 | ||
24 | 24 | let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA' | |
25 | 25 | ||
26 | 26 | let ethAssetId = base58'3JJkzB4pFXcqdJvC9TcV8ys1FLgesr5SxbhmykkpceQp' | |
27 | 27 | ||
28 | 28 | let usdnAssetId = base58'9Nf5wpj6jds3VRZKDryp6Dtf3R9d8MdbjNhencLogCr5' | |
29 | 29 | ||
30 | 30 | let adminPublicKey = base58'7zDUSbBXZtec3E333b1fC2wR2MPrnzh69ZrH3rwpQj9S' | |
31 | 31 | ||
32 | 32 | let feeAddress = Address(base58'3N7G2kVtBTh94aEnDHQ9dpi4EdsDxAiDXjB') | |
33 | 33 | ||
34 | 34 | func getIntKeyDataOrError (key) = { | |
35 | 35 | let v = valueOrErrorMessage(getInteger(this, key), "unable to read key") | |
36 | 36 | v | |
37 | 37 | } | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getIntKeyData (key) = { | |
41 | 41 | let v = valueOrElse(getInteger(this, key), 0) | |
42 | 42 | v | |
43 | 43 | } | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getTotalFeeByKey (key) = getIntKeyData(key) | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getFeeAmount (amount) = { | |
50 | 50 | let fee = getIntKeyDataOrError(feeKey) | |
51 | 51 | let feeAmount = fraction(amount, fee, 10000) | |
52 | 52 | feeAmount | |
53 | 53 | } | |
54 | 54 | ||
55 | 55 | ||
56 | 56 | func getFeeKeyByAssetId (assetId) = if ((assetId == usdnAssetId)) | |
57 | 57 | then totalFeeUsdKey | |
58 | 58 | else if ((assetId == ethAssetId)) | |
59 | 59 | then totalFeeEthKey | |
60 | 60 | else if ((assetId == dyzraptAssetId)) | |
61 | 61 | then totalFeeDyzraptKey | |
62 | 62 | else throw("Incorrect asset attached") | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | func getUsdnDyzAmount (assetId,amount) = { | |
66 | 66 | let feeAmount = getFeeAmount(amount) | |
67 | 67 | let amountWithoutFee = (amount - feeAmount) | |
68 | 68 | let balanceA = getIntegerValue(this, usdnDyzABalanceKey) | |
69 | 69 | let balanceB = getIntegerValue(this, usdnDyzBBalanceKey) | |
70 | 70 | if ((assetId == usdnAssetId)) | |
71 | 71 | then { | |
72 | 72 | let rAmount = fraction(balanceB, amountWithoutFee, (amountWithoutFee + balanceA)) | |
73 | 73 | let rAssetId = dyzraptAssetId | |
74 | 74 | let newBalanceA = (amountWithoutFee + balanceA) | |
75 | 75 | let newBalanceB = (balanceB - rAmount) | |
76 | 76 | $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB) | |
77 | 77 | } | |
78 | 78 | else if ((assetId == dyzraptAssetId)) | |
79 | 79 | then { | |
80 | 80 | let rAmount = fraction(balanceA, amountWithoutFee, (amountWithoutFee + balanceB)) | |
81 | 81 | let rAssetId = usdnAssetId | |
82 | 82 | let newBalanceA = (balanceA - rAmount) | |
83 | 83 | let newBalanceB = (balanceB + amountWithoutFee) | |
84 | 84 | $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB) | |
85 | 85 | } | |
86 | 86 | else throw("Incorrect asset attached") | |
87 | 87 | } | |
88 | 88 | ||
89 | 89 | ||
90 | 90 | @Callable(i) | |
91 | 91 | func initUsdnDyzPair () = if (isDefined(getBoolean(this, usdnDyzPairIsActiveKey))) | |
92 | 92 | then throw("Pair is already active") | |
93 | 93 | else if ((i.callerPublicKey != adminPublicKey)) | |
94 | 94 | then throw("Only admin can activate pair") | |
95 | 95 | else { | |
96 | 96 | let $t029753052 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
97 | 97 | let pmtAmountA = $t029753052._1 | |
98 | 98 | let pmtAssetIdA = $t029753052._2 | |
99 | 99 | let $t030613138 = $Tuple2(i.payments[1].amount, i.payments[1].assetId) | |
100 | 100 | let pmtAmountB = $t030613138._1 | |
101 | 101 | let pmtAssetIdB = $t030613138._2 | |
102 | 102 | if ((pmtAssetIdA != usdnAssetId)) | |
103 | 103 | then throw("A asset is not a usdn") | |
104 | 104 | else if ((pmtAssetIdB != dyzraptAssetId)) | |
105 | 105 | then throw("B asset is not a dyzrupt") | |
106 | 106 | else [BooleanEntry(usdnDyzPairIsActiveKey, true), IntegerEntry(usdnDyzABalanceKey, pmtAmountA), IntegerEntry(usdnDyzBBalanceKey, pmtAmountB), IntegerEntry(feeKey, 300)] | |
107 | 107 | } | |
108 | 108 | ||
109 | 109 | ||
110 | 110 | ||
111 | 111 | @Callable(i) | |
112 | - | func exchangeUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey)))) | |
112 | + | func exchangeUsdnDyz (minReceive) = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey)))) | |
113 | 113 | then throw("Pair is not active") | |
114 | 114 | else { | |
115 | 115 | let pmt = value(i.payments[0]) | |
116 | 116 | let assetId = pmt.assetId | |
117 | 117 | let amount = pmt.amount | |
118 | 118 | if (if ((assetId != usdnAssetId)) | |
119 | 119 | then (assetId != dyzraptAssetId) | |
120 | 120 | else false) | |
121 | 121 | then throw("Only usdn and dyzrupt are supporting") | |
122 | 122 | 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) | |
131 | 134 | [IntegerEntry(usdnDyzABalanceKey, newBalanceA), IntegerEntry(usdnDyzBBalanceKey, newBalanceB), IntegerEntry(totalFeeKey, totalFee), ScriptTransfer(feeAddress, feeAmount, assetId), ScriptTransfer(i.caller, rAmount, rAssetId)] | |
135 | + | } | |
132 | 136 | } | |
133 | 137 | } | |
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 | + | } | |
134 | 165 | ||
135 | 166 |
github/deemru/w8io/169f3d6 32.66 ms ◑