tx · AXswYCqiUSgcsNMo7V3gYSxWCSwm4ubtQJrvWrL8yYiu 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S: -0.01400000 Waves 2021.04.03 09:43 [1465918] smart account 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S > SELF 0.00000000 Waves
{ "type": 13, "id": "AXswYCqiUSgcsNMo7V3gYSxWCSwm4ubtQJrvWrL8yYiu", "fee": 1400000, "feeAssetId": null, "timestamp": 1617432226870, "version": 2, "chainId": 84, "sender": "3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S", "senderPublicKey": "CgByewRUvLk7UtWSfRMLSYw4Ap2wT5dcdVYKideqDp9M", "proofs": [ "5WHeex7FzkQL1fZdSULYjujgmaApQc11Wp4EGCG67ocyEDhvoB8eqH1sTjAozBWkkaifvHP1ATNVKhqJ9bYA3gN4" ], "script": "base64:AAIEAAAAAAAAAAwIAhIAEgASABIAEgAAAAAQAAAAAA50b3RhbEZlZUV0aEtleQIAAAANdG90YWxfZmVlX2V0aAAAAAAOdG90YWxGZWVVc2RLZXkCAAAADXRvdGFsX2ZlZV91c2QAAAAAEnRvdGFsRmVlRHl6cmFwdEtleQIAAAARdG90YWxfZmVlX2R5enJhcHQAAAAAEXByaWNlT2ZEeXpyYXB0S2V5AgAAAANkeXoAAAAADXByaWNlT2ZFdGhLZXkCAAAAA2V0aAAAAAANb3JhY2xlQWRkcmVzcwkBAAAAB0FkZHJlc3MAAAABAQAAABoBVL4/7s2JD7wFpgWNJdKO/aqFvcIdJFtzlgAAAAAOZHl6cmFwdEFzc2V0SWQBAAAAIJ8Z6XPZJu9QR4hmGj9/o7LyMJ48jRPQD0CePJOEpwQjAAAAAApldGhBc3NldElkAQAAACAiJlO6kpv9VYDdwqxzfY0rRQ9rtHAOIBs/eo3GguMLoQAAAAALdXNkbkFzc2V0SWQBAAAAIHxpwWtkcIB0JFIbiNXtI38nVRmozWmXoaigru9h4HfCAQAAAAxnZXRGZWVBbW91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kBAAAAAiE9AAAAAgUAAAAHYXNzZXRJZAUAAAAOZHl6cmFwdEFzc2V0SWQJAAACAAAAAQIAAAAsT25seSBEWVpSQVBUIHRva2VucyBhcmUgYWxsb3dlZCBmb3Igc3dhcHBpbmcEAAAAA2ZlZQkBAAAADGdldEZlZUFtb3VudAAAAAEFAAAAC3RvdGFsQW1vdW50BAAAAAZhbW91bnQJAABlAAAAAgUAAAALdG90YWxBbW91bnQFAAAAA2ZlZQQAAAAKdXNkbkFtb3VudAkBAAAADWR5enJhcHRUb1VzZG4AAAABBQAAAAZhbW91bnQEAAAACGV0aFByaWNlCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQaAAAAAgUAAAANb3JhY2xlQWRkcmVzcwUAAAANcHJpY2VPZkV0aEtleQIAAAAUVW5hYmxlIHRvIGxvYWQgcHJpY2UEAAAACWV0aEFtb3VudAkAAGsAAAADBQAAAAp1c2RuQW1vdW50AAAAAAAAACcQBQAAAAhldGhQcmljZQQAAAAIc2F2ZWRGZWUJAQAAABJnZXRUb3RhbEZlZUR5enJhcHQAAAAABAAAAAh0b3RhbEZlZQkAAGQAAAACBQAAAAhzYXZlZEZlZQUAAAADZmVlCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAABJ0b3RhbEZlZUR5enJhcHRLZXkFAAAACHRvdGFsRmVlCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAJZXRoQW1vdW50BQAAAApldGhBc3NldElkBQAAAANuaWwAAAAAePIwhw==", "height": 1465918, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7f6YdXZ6iZt2Wh1sF2ZXYe5rRqCAasqoZ6RpExkGM423 Next: 7SLtRq6DWjUvBpCPkKddSz5u1vFwmFezZFTYvrXvJ2o Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let totalFeeEthKey = "total_fee_eth" | |
5 | 5 | ||
6 | 6 | let totalFeeUsdKey = "total_fee_usd" | |
7 | 7 | ||
8 | 8 | let totalFeeDyzraptKey = "total_fee_dyzrapt" | |
9 | 9 | ||
10 | 10 | let priceOfDyzraptKey = "dyz" | |
11 | 11 | ||
12 | 12 | let priceOfEthKey = "eth" | |
13 | 13 | ||
14 | 14 | let oracleAddress = Address(base58'3N7G2kVtBTh94aEnDHQ9dpi4EdsDxAiDXjB') | |
15 | 15 | ||
16 | 16 | let dyzraptAssetId = base58'Bi4jxKEFjjYG2emeyxZfpkVMS88N7uAogHNsi1urkoJA' | |
17 | 17 | ||
18 | 18 | let ethAssetId = base58'3JJkzB4pFXcqdJvC9TcV8ys1FLgesr5SxbhmykkpceQp' | |
19 | 19 | ||
20 | 20 | let usdnAssetId = base58'9Nf5wpj6jds3VRZKDryp6Dtf3R9d8MdbjNhencLogCr5' | |
21 | 21 | ||
22 | 22 | func getFeeAmount (amount) = { | |
23 | 23 | let fee = fraction(amount, 3, 100) | |
24 | 24 | fee | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getIntKeyData (key) = { | |
29 | 29 | let v = valueOrElse(getInteger(this, key), 0) | |
30 | 30 | v | |
31 | 31 | } | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getTotalFeeEth () = getIntKeyData(totalFeeEthKey) | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func getTotalFeeUsd () = getIntKeyData(totalFeeUsdKey) | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getTotalFeeDyzrapt () = getIntKeyData(totalFeeDyzraptKey) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func usdnToDyzrapt (amount) = { | |
44 | 44 | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfDyzraptKey), "Unable to load price") | |
45 | 45 | fraction(amount, 10000, dyzraptPrice) | |
46 | 46 | } | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func dyzraptToUsdn (amount) = { | |
50 | 50 | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfDyzraptKey), "Unable to load price") | |
51 | 51 | fraction(amount, dyzraptPrice, 10000) | |
52 | 52 | } | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | @Callable(i) | |
56 | 56 | func test () = { | |
57 | 57 | let pmt = value(i.payments[0]) | |
58 | 58 | let assetId = pmt.assetId | |
59 | 59 | let amount = pmt.amount | |
60 | 60 | if ((assetId == dyzraptAssetId)) | |
61 | 61 | then throw(("its a dyzrapt. Amount=" + toString(amount))) | |
62 | 62 | else throw("its not a dyzrapt") | |
63 | 63 | } | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | ||
67 | 67 | @Callable(i) | |
68 | 68 | func swapUsdnToDyzrapt () = { | |
69 | 69 | let pmt = value(i.payments[0]) | |
70 | 70 | let assetId = pmt.assetId | |
71 | 71 | let totalAmount = pmt.amount | |
72 | 72 | if ((assetId != usdnAssetId)) | |
73 | 73 | then throw("Only USDN tokens are allowed for swapping") | |
74 | 74 | else { | |
75 | 75 | let fee = getFeeAmount(totalAmount) | |
76 | 76 | let amount = (totalAmount - fee) | |
77 | 77 | let dyzraptAmount = usdnToDyzrapt(amount) | |
78 | 78 | let savedFee = getTotalFeeUsd() | |
79 | 79 | let totalFee = (savedFee + fee) | |
80 | 80 | [IntegerEntry(totalFeeUsdKey, totalFee), ScriptTransfer(i.caller, dyzraptAmount, dyzraptAssetId)] | |
81 | 81 | } | |
82 | 82 | } | |
83 | 83 | ||
84 | 84 | ||
85 | 85 | ||
86 | 86 | @Callable(i) | |
87 | 87 | func swapEthToDyzrapt () = { | |
88 | 88 | let pmt = value(i.payments[0]) | |
89 | 89 | let assetId = pmt.assetId | |
90 | 90 | let totalAmount = pmt.amount | |
91 | 91 | if ((assetId != ethAssetId)) | |
92 | 92 | then throw("Only WETH tokens are allowed for swapping") | |
93 | 93 | else { | |
94 | 94 | let fee = getFeeAmount(totalAmount) | |
95 | 95 | let amount = (totalAmount - fee) | |
96 | 96 | let ethPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfEthKey), "Unable to load price") | |
97 | 97 | let usdnAmount = fraction(amount, ethPrice, 10000) | |
98 | 98 | let dyzraptAmount = usdnToDyzrapt(usdnAmount) | |
99 | 99 | let savedFee = getTotalFeeEth() | |
100 | 100 | let totalFee = (savedFee + fee) | |
101 | 101 | [IntegerEntry(totalFeeEthKey, totalFee), ScriptTransfer(i.caller, dyzraptAmount, dyzraptAssetId)] | |
102 | 102 | } | |
103 | 103 | } | |
104 | 104 | ||
105 | 105 | ||
106 | 106 | ||
107 | 107 | @Callable(i) | |
108 | 108 | func swapDyzraptToUsdn () = { | |
109 | 109 | let pmt = value(i.payments[0]) | |
110 | 110 | let assetId = pmt.assetId | |
111 | 111 | let totalAmount = pmt.amount | |
112 | 112 | if ((assetId != dyzraptAssetId)) | |
113 | 113 | then throw("Only DYZRAPT tokens are allowed for swapping") | |
114 | 114 | else { | |
115 | 115 | let fee = getFeeAmount(totalAmount) | |
116 | 116 | let amount = (totalAmount - fee) | |
117 | 117 | let usdnAmount = dyzraptToUsdn(amount) | |
118 | 118 | let savedFee = getTotalFeeDyzrapt() | |
119 | 119 | let totalFee = (savedFee + fee) | |
120 | 120 | [IntegerEntry(totalFeeDyzraptKey, totalFee), ScriptTransfer(i.caller, usdnAmount, usdnAssetId)] | |
121 | 121 | } | |
122 | 122 | } | |
123 | 123 | ||
124 | 124 | ||
125 | 125 | ||
126 | 126 | @Callable(i) | |
127 | 127 | func swapDyzraptToEth () = { | |
128 | 128 | let pmt = value(i.payments[0]) | |
129 | 129 | let assetId = pmt.assetId | |
130 | 130 | let totalAmount = pmt.amount | |
131 | 131 | if ((assetId != dyzraptAssetId)) | |
132 | 132 | then throw("Only DYZRAPT tokens are allowed for swapping") | |
133 | 133 | else { | |
134 | 134 | let fee = getFeeAmount(totalAmount) | |
135 | 135 | let amount = (totalAmount - fee) | |
136 | 136 | let usdnAmount = dyzraptToUsdn(amount) | |
137 | 137 | let ethPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfEthKey), "Unable to load price") | |
138 | 138 | let ethAmount = fraction(usdnAmount, 10000, ethPrice) | |
139 | 139 | let savedFee = getTotalFeeDyzrapt() | |
140 | 140 | let totalFee = (savedFee + fee) | |
141 | 141 | [IntegerEntry(totalFeeDyzraptKey, totalFee), ScriptTransfer(i.caller, ethAmount, ethAssetId)] | |
142 | 142 | } | |
143 | 143 | } | |
144 | 144 | ||
145 | 145 |
github/deemru/w8io/026f985 31.84 ms ◑