tx · H3Ps2DpcnSkvWMZwgPrUc7AH59fe5ZoA4KM1MTX6on4C 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S: -0.01400000 Waves 2021.04.03 20:52 [1466585] smart account 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S > SELF 0.00000000 Waves
{ "type": 13, "id": "H3Ps2DpcnSkvWMZwgPrUc7AH59fe5ZoA4KM1MTX6on4C", "fee": 1400000, "feeAssetId": null, "timestamp": 1617472364134, "version": 2, "chainId": 84, "sender": "3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S", "senderPublicKey": "CgByewRUvLk7UtWSfRMLSYw4Ap2wT5dcdVYKideqDp9M", "proofs": [ "46FJDGJhUfGrUERF4brd5cVnWRGi94JivuTHoFGikr4cYXxdMLWq9kU1fGwPoK7gpP9xxAfFSJ5FJizg85CrjaiY" ], "script": "base64:AAIEAAAAAAAAAAYIAhIAEgAAAAAVAAAAABJ1c2RuRHl6QUJhbGFuY2VLZXkCAAAAGHVzZG5fZHl6X2FfYXNzZXRfYmFsYW5jZQAAAAASdXNkbkR5ekJCYWxhbmNlS2V5AgAAABh1c2RuX2R5el9iX2Fzc2V0X2JhbGFuY2UAAAAAEWV0aER5ekFCYWxhbmNlS2V5AgAAABdldGhfZHl6X2FfYXNzZXRfYmFsYW5jZQAAAAARZXRoRHl6QkJhbGFuY2VLZXkCAAAAF2V0aF9keXpfYl9hc3NldF9iYWxhbmNlAAAAABZ1c2RuRHl6UGFpcklzQWN0aXZlS2V5AgAAABJ1c2RuX2R5el9pc19hY3RpdmUAAAAAFWV0aER5elBhaXJJc0FjdGl2ZUtleQIAAAARZXRoX2R5el9pc19hY3RpdmUAAAAABmZlZUtleQIAAAADZmVlAAAAAA50b3RhbEZlZUV0aEtleQIAAAANdG90YWxfZmVlX2V0aAAAAAAOdG90YWxGZWVVc2RLZXkCAAAADXRvdGFsX2ZlZV91c2QAAAAAEnRvdGFsRmVlRHl6cmFwdEtleQIAAA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WRkcmVzcwUAAAAJZmVlQW1vdW50BQAAAAdhc3NldElkCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAHckFtb3VudAUAAAAIckFzc2V0SWQFAAAAA25pbAAAAADm6rN6", "height": 1466585, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4dfpS3GLNgEQDED9XT9LX6zYJ2u1mggW8XRWXmU81PSn Next: 2oQ3QJHoAg5mVsXyP6N3VMg76M81bCkePLi3KJ1oU9KX Diff:
Old | New | Differences | |
---|---|---|---|
15 | 15 | ||
16 | 16 | let feeKey = "fee" | |
17 | 17 | ||
18 | + | let totalFeeEthKey = "total_fee_eth" | |
19 | + | ||
20 | + | let totalFeeUsdKey = "total_fee_usd" | |
21 | + | ||
22 | + | let totalFeeDyzraptKey = "total_fee_dyzrapt" | |
23 | + | ||
18 | 24 | let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA' | |
19 | 25 | ||
20 | 26 | let ethAssetId = base58'3JJkzB4pFXcqdJvC9TcV8ys1FLgesr5SxbhmykkpceQp' | |
31 | 37 | } | |
32 | 38 | ||
33 | 39 | ||
40 | + | func getIntKeyData (key) = { | |
41 | + | let v = valueOrElse(getInteger(this, key), 0) | |
42 | + | v | |
43 | + | } | |
44 | + | ||
45 | + | ||
46 | + | func getTotalFeeByKey (key) = getIntKeyData(key) | |
47 | + | ||
48 | + | ||
34 | 49 | func getFeeAmount (amount) = { | |
35 | 50 | let fee = getIntKeyDataOrError(feeKey) | |
36 | 51 | let feeAmount = fraction(amount, fee, 10000) | |
37 | 52 | feeAmount | |
38 | 53 | } | |
54 | + | ||
55 | + | ||
56 | + | func getFeeKeyByAssetId (assetId) = if ((assetId == usdnAssetId)) | |
57 | + | then totalFeeUsdKey | |
58 | + | else if ((assetId == ethAssetId)) | |
59 | + | then totalFeeEthKey | |
60 | + | else if ((assetId == dyzraptAssetId)) | |
61 | + | then totalFeeDyzraptKey | |
62 | + | else throw("Incorrect asset attached") | |
39 | 63 | ||
40 | 64 | ||
41 | 65 | func getUsdnDyzAmount (assetId,amount) = { | |
46 | 70 | if ((assetId == usdnAssetId)) | |
47 | 71 | then { | |
48 | 72 | let rAmount = fraction(balanceB, amountWithoutFee, (amountWithoutFee + balanceA)) | |
49 | - | throw(("usdn" + toString(rAmount))) | |
73 | + | let rAssetId = dyzraptAssetId | |
74 | + | let newBalanceA = (amountWithoutFee + balanceA) | |
75 | + | let newBalanceB = (balanceB - rAmount) | |
76 | + | $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB) | |
50 | 77 | } | |
51 | 78 | else if ((assetId == dyzraptAssetId)) | |
52 | 79 | then { | |
53 | 80 | let rAmount = fraction(balanceA, amountWithoutFee, (amountWithoutFee + balanceB)) | |
54 | - | throw(("dyzrupt " + toString(rAmount))) | |
81 | + | let rAssetId = usdnAssetId | |
82 | + | let newBalanceA = (balanceA - rAmount) | |
83 | + | let newBalanceB = (balanceB + amountWithoutFee) | |
84 | + | $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB) | |
55 | 85 | } | |
56 | 86 | else throw("Incorrect asset attached") | |
57 | 87 | } | |
63 | 93 | else if ((i.callerPublicKey != adminPublicKey)) | |
64 | 94 | then throw("Only admin can activate pair") | |
65 | 95 | else { | |
66 | - | let $ | |
67 | - | let pmtAmountA = $ | |
68 | - | let pmtAssetIdA = $ | |
69 | - | let $ | |
70 | - | let pmtAmountB = $ | |
71 | - | let pmtAssetIdB = $ | |
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 | |
72 | 102 | if ((pmtAssetIdA != usdnAssetId)) | |
73 | 103 | then throw("A asset is not a usdn") | |
74 | 104 | else if ((pmtAssetIdB != dyzraptAssetId)) | |
90 | 120 | else false) | |
91 | 121 | then throw("Only usdn and dyzrupt are supporting") | |
92 | 122 | else { | |
93 | - | let rAmount = getUsdnDyzAmount(assetId, amount) | |
94 | - | throw(rAmount) | |
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) | |
131 | + | [IntegerEntry(usdnDyzABalanceKey, newBalanceA), IntegerEntry(usdnDyzBBalanceKey, newBalanceB), IntegerEntry(totalFeeKey, totalFee), ScriptTransfer(feeAddress, feeAmount, assetId), ScriptTransfer(i.caller, rAmount, rAssetId)] | |
95 | 132 | } | |
96 | 133 | } | |
97 | 134 |
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 | + | let totalFeeEthKey = "total_fee_eth" | |
19 | + | ||
20 | + | let totalFeeUsdKey = "total_fee_usd" | |
21 | + | ||
22 | + | let totalFeeDyzraptKey = "total_fee_dyzrapt" | |
23 | + | ||
18 | 24 | let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA' | |
19 | 25 | ||
20 | 26 | let ethAssetId = base58'3JJkzB4pFXcqdJvC9TcV8ys1FLgesr5SxbhmykkpceQp' | |
21 | 27 | ||
22 | 28 | let usdnAssetId = base58'9Nf5wpj6jds3VRZKDryp6Dtf3R9d8MdbjNhencLogCr5' | |
23 | 29 | ||
24 | 30 | let adminPublicKey = base58'7zDUSbBXZtec3E333b1fC2wR2MPrnzh69ZrH3rwpQj9S' | |
25 | 31 | ||
26 | 32 | let feeAddress = Address(base58'3N7G2kVtBTh94aEnDHQ9dpi4EdsDxAiDXjB') | |
27 | 33 | ||
28 | 34 | func getIntKeyDataOrError (key) = { | |
29 | 35 | let v = valueOrErrorMessage(getInteger(this, key), "unable to read key") | |
30 | 36 | v | |
31 | 37 | } | |
32 | 38 | ||
33 | 39 | ||
40 | + | func getIntKeyData (key) = { | |
41 | + | let v = valueOrElse(getInteger(this, key), 0) | |
42 | + | v | |
43 | + | } | |
44 | + | ||
45 | + | ||
46 | + | func getTotalFeeByKey (key) = getIntKeyData(key) | |
47 | + | ||
48 | + | ||
34 | 49 | func getFeeAmount (amount) = { | |
35 | 50 | let fee = getIntKeyDataOrError(feeKey) | |
36 | 51 | let feeAmount = fraction(amount, fee, 10000) | |
37 | 52 | feeAmount | |
38 | 53 | } | |
54 | + | ||
55 | + | ||
56 | + | func getFeeKeyByAssetId (assetId) = if ((assetId == usdnAssetId)) | |
57 | + | then totalFeeUsdKey | |
58 | + | else if ((assetId == ethAssetId)) | |
59 | + | then totalFeeEthKey | |
60 | + | else if ((assetId == dyzraptAssetId)) | |
61 | + | then totalFeeDyzraptKey | |
62 | + | else throw("Incorrect asset attached") | |
39 | 63 | ||
40 | 64 | ||
41 | 65 | func getUsdnDyzAmount (assetId,amount) = { | |
42 | 66 | let feeAmount = getFeeAmount(amount) | |
43 | 67 | let amountWithoutFee = (amount - feeAmount) | |
44 | 68 | let balanceA = getIntegerValue(this, usdnDyzABalanceKey) | |
45 | 69 | let balanceB = getIntegerValue(this, usdnDyzBBalanceKey) | |
46 | 70 | if ((assetId == usdnAssetId)) | |
47 | 71 | then { | |
48 | 72 | let rAmount = fraction(balanceB, amountWithoutFee, (amountWithoutFee + balanceA)) | |
49 | - | throw(("usdn" + toString(rAmount))) | |
73 | + | let rAssetId = dyzraptAssetId | |
74 | + | let newBalanceA = (amountWithoutFee + balanceA) | |
75 | + | let newBalanceB = (balanceB - rAmount) | |
76 | + | $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB) | |
50 | 77 | } | |
51 | 78 | else if ((assetId == dyzraptAssetId)) | |
52 | 79 | then { | |
53 | 80 | let rAmount = fraction(balanceA, amountWithoutFee, (amountWithoutFee + balanceB)) | |
54 | - | throw(("dyzrupt " + toString(rAmount))) | |
81 | + | let rAssetId = usdnAssetId | |
82 | + | let newBalanceA = (balanceA - rAmount) | |
83 | + | let newBalanceB = (balanceB + amountWithoutFee) | |
84 | + | $Tuple5(feeAmount, rAmount, rAssetId, newBalanceA, newBalanceB) | |
55 | 85 | } | |
56 | 86 | else throw("Incorrect asset attached") | |
57 | 87 | } | |
58 | 88 | ||
59 | 89 | ||
60 | 90 | @Callable(i) | |
61 | 91 | func initUsdnDyzPair () = if (isDefined(getBoolean(this, usdnDyzPairIsActiveKey))) | |
62 | 92 | then throw("Pair is already active") | |
63 | 93 | else if ((i.callerPublicKey != adminPublicKey)) | |
64 | 94 | then throw("Only admin can activate pair") | |
65 | 95 | else { | |
66 | - | let $ | |
67 | - | let pmtAmountA = $ | |
68 | - | let pmtAssetIdA = $ | |
69 | - | let $ | |
70 | - | let pmtAmountB = $ | |
71 | - | let pmtAssetIdB = $ | |
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 | |
72 | 102 | if ((pmtAssetIdA != usdnAssetId)) | |
73 | 103 | then throw("A asset is not a usdn") | |
74 | 104 | else if ((pmtAssetIdB != dyzraptAssetId)) | |
75 | 105 | then throw("B asset is not a dyzrupt") | |
76 | 106 | else [BooleanEntry(usdnDyzPairIsActiveKey, true), IntegerEntry(usdnDyzABalanceKey, pmtAmountA), IntegerEntry(usdnDyzBBalanceKey, pmtAmountB), IntegerEntry(feeKey, 300)] | |
77 | 107 | } | |
78 | 108 | ||
79 | 109 | ||
80 | 110 | ||
81 | 111 | @Callable(i) | |
82 | 112 | func exchangeUsdnDyz () = if (!(isDefined(getBoolean(this, usdnDyzPairIsActiveKey)))) | |
83 | 113 | then throw("Pair is not active") | |
84 | 114 | else { | |
85 | 115 | let pmt = value(i.payments[0]) | |
86 | 116 | let assetId = pmt.assetId | |
87 | 117 | let amount = pmt.amount | |
88 | 118 | if (if ((assetId != usdnAssetId)) | |
89 | 119 | then (assetId != dyzraptAssetId) | |
90 | 120 | else false) | |
91 | 121 | then throw("Only usdn and dyzrupt are supporting") | |
92 | 122 | else { | |
93 | - | let rAmount = getUsdnDyzAmount(assetId, amount) | |
94 | - | throw(rAmount) | |
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) | |
131 | + | [IntegerEntry(usdnDyzABalanceKey, newBalanceA), IntegerEntry(usdnDyzBBalanceKey, newBalanceB), IntegerEntry(totalFeeKey, totalFee), ScriptTransfer(feeAddress, feeAmount, assetId), ScriptTransfer(i.caller, rAmount, rAssetId)] | |
95 | 132 | } | |
96 | 133 | } | |
97 | 134 | ||
98 | 135 |
github/deemru/w8io/169f3d6 24.26 ms ◑