tx · 5R5BHKikDAGwFGHyA72uMjcsx5XfXsQJNRvZmsmcyxUB 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S: -0.01400000 Waves 2021.03.26 23:42 [1455204] smart account 3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S > SELF 0.00000000 Waves
{ "type": 13, "id": "5R5BHKikDAGwFGHyA72uMjcsx5XfXsQJNRvZmsmcyxUB", "fee": 1400000, "feeAssetId": null, "timestamp": 1616791367112, "version": 2, "chainId": 84, "sender": "3MwLcJy3MSb2kq6dUaUR5uBgm8zCKZMjz2S", "senderPublicKey": "CgByewRUvLk7UtWSfRMLSYw4Ap2wT5dcdVYKideqDp9M", "proofs": [ "2mg1d45Fq2mdvF8rX4g2AbNZK7eaMa7MkvwwtR44hBUJ9A8W5Fub5jrLfMk4P4h4aK7AanAX8tLVNdoHtYxSq3mS" ], "script": "base64:AAIEAAAAAAAAAAoIAhIAEgASABIAAAAAEAAAAAAOdG90YWxGZWVFdGhLZXkCAAAADXRvdGFsX2ZlZV9ldGgAAAAADnRvdGFsRmVlVXNkS2V5AgAAAA10b3RhbF9mZWVfdXNkAAAAABJ0b3RhbEZlZUR5enJhcHRLZXkCAAAAEXRvdGFsX2ZlZV9keXpyYXB0AAAAABFwcmljZU9mRHl6cmFwdEtleQIAAAADZHl6AAAAAA1wcmljZU9mRXRoS2V5AgAAAANldGgAAAAADW9yYWNsZUFkZHJlc3MJAQAAAAdBZGRyZXNzAAAAAQEAAAAaAVS+P+7NiQ+8BaYFjSXSjv2qhb3CHSRbc5YAAAAADmR5enJhcHRBc3NldElkAQAAACCfGelz2SbvUEeIZho/f6Oy8jCePI0T0A9AnjyThKcEIwAAAAAKZXRoQXNzZXRJZAEAAAAgIiZTupKb/VWA3cKsc32NK0UPa7RwDiAbP3qNxoLjC6EAAAAAC3VzZG5Bc3NldElkAQAAACB8acFrZHCAdCRSG4jV7SN/J1UZqM1pl6GooK7vYeB3wgEAAAAMZ2V0RmVlQW1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EFtb3VudAUAAAAOZHl6cmFwdEFzc2V0SWQFAAAAA25pbAAAAAFpAQAAABFzd2FwRHl6cmFwdFRvVXNkbgAAAAAEAAAAA3BtdAkBAAAABXZhbHVlAAAAAQkAAZEAAAACCAUAAAABaQAAAAhwYXltZW50cwAAAAAAAAAAAAQAAAAHYXNzZXRJZAgFAAAAA3BtdAAAAAdhc3NldElkBAAAAAt0b3RhbEFtb3VudAgFAAAAA3BtdAAAAAZhbW91bnQDCQEAAAACIT0AAAACBQAAAAdhc3NldElkBQAAAA5keXpyYXB0QXNzZXRJZAkAAAIAAAABAgAAACxPbmx5IERZWlJBUFQgdG9rZW5zIGFyZSBhbGxvd2VkIGZvciBzd2FwcGluZwQAAAADZmVlCQEAAAAMZ2V0RmVlQW1vdW50AAAAAQUAAAALdG90YWxBbW91bnQEAAAABmFtb3VudAkAAGUAAAACBQAAAAt0b3RhbEFtb3VudAUAAAADZmVlBAAAAAp1c2RuQW1vdW50CQEAAAANZHl6cmFwdFRvVXNkbgAAAAEFAAAABmFtb3VudAQAAAAIc2F2ZWRGZWUJAQAAABJnZXRUb3RhbEZlZUR5enJhcHQAAAAABAAAAAh0b3RhbEZlZQkAAGQAAAACBQAAAAhzYXZlZEZlZQUAAAADZmVlCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAA50b3RhbEZlZVVzZEtleQUAAAAIdG90YWxGZWUJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAp1c2RuQW1vdW50BQAAAAt1c2RuQXNzZXRJZAUAAAADbmlsAAAAAPEs+Hc=", "height": 1455204, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3sPLws5tXwicZQGq4hv1AaDf27Z369MFXcftqpGZsoHa Next: 2YNjFpGgKgw4E9zFmqoJ3auPoUMF72DbQ1qQtGd6gBTS Diff:
Old | New | Differences | |
---|---|---|---|
46 | 46 | } | |
47 | 47 | ||
48 | 48 | ||
49 | + | func dyzraptToUsdn (amount) = { | |
50 | + | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfDyzraptKey), "Unable to load price") | |
51 | + | fraction(amount, dyzraptPrice, 10000) | |
52 | + | } | |
53 | + | ||
54 | + | ||
49 | 55 | @Callable(i) | |
50 | 56 | func test () = { | |
51 | 57 | let pmt = value(i.payments[0]) | |
64 | 70 | let assetId = pmt.assetId | |
65 | 71 | let totalAmount = pmt.amount | |
66 | 72 | if ((assetId != usdnAssetId)) | |
67 | - | then throw("Only | |
73 | + | then throw("Only USDN tokens are allowed for swapping") | |
68 | 74 | else { | |
69 | 75 | let fee = getFeeAmount(totalAmount) | |
70 | 76 | let amount = (totalAmount - fee) | |
83 | 89 | let assetId = pmt.assetId | |
84 | 90 | let totalAmount = pmt.amount | |
85 | 91 | if ((assetId != ethAssetId)) | |
86 | - | then throw("Only | |
92 | + | then throw("Only WETH tokens are allowed for swapping") | |
87 | 93 | else { | |
88 | 94 | let fee = getFeeAmount(totalAmount) | |
89 | 95 | let amount = (totalAmount - fee) | |
97 | 103 | } | |
98 | 104 | ||
99 | 105 | ||
106 | + | ||
107 | + | @Callable(i) | |
108 | + | func swapDyzraptToUsdn () = { | |
109 | + | let pmt = value(i.payments[0]) | |
110 | + | let assetId = pmt.assetId | |
111 | + | let totalAmount = pmt.amount | |
112 | + | if ((assetId != dyzraptAssetId)) | |
113 | + | then throw("Only DYZRAPT tokens are allowed for swapping") | |
114 | + | else { | |
115 | + | let fee = getFeeAmount(totalAmount) | |
116 | + | let amount = (totalAmount - fee) | |
117 | + | let usdnAmount = dyzraptToUsdn(amount) | |
118 | + | let savedFee = getTotalFeeDyzrapt() | |
119 | + | let totalFee = (savedFee + fee) | |
120 | + | [IntegerEntry(totalFeeUsdKey, totalFee), ScriptTransfer(i.caller, usdnAmount, usdnAssetId)] | |
121 | + | } | |
122 | + | } | |
123 | + | ||
124 | + |
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 | + | func dyzraptToUsdn (amount) = { | |
50 | + | let dyzraptPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfDyzraptKey), "Unable to load price") | |
51 | + | fraction(amount, dyzraptPrice, 10000) | |
52 | + | } | |
53 | + | ||
54 | + | ||
49 | 55 | @Callable(i) | |
50 | 56 | func test () = { | |
51 | 57 | let pmt = value(i.payments[0]) | |
52 | 58 | let assetId = pmt.assetId | |
53 | 59 | let amount = pmt.amount | |
54 | 60 | if ((assetId == dyzraptAssetId)) | |
55 | 61 | then throw(("its a dyzrapt. Amount=" + toString(amount))) | |
56 | 62 | else throw("its not a dyzrapt") | |
57 | 63 | } | |
58 | 64 | ||
59 | 65 | ||
60 | 66 | ||
61 | 67 | @Callable(i) | |
62 | 68 | func swapUsdnToDyzrapt () = { | |
63 | 69 | let pmt = value(i.payments[0]) | |
64 | 70 | let assetId = pmt.assetId | |
65 | 71 | let totalAmount = pmt.amount | |
66 | 72 | if ((assetId != usdnAssetId)) | |
67 | - | then throw("Only | |
73 | + | then throw("Only USDN tokens are allowed for swapping") | |
68 | 74 | else { | |
69 | 75 | let fee = getFeeAmount(totalAmount) | |
70 | 76 | let amount = (totalAmount - fee) | |
71 | 77 | let dyzraptAmount = usdnToDyzrapt(amount) | |
72 | 78 | let savedFee = getTotalFeeUsd() | |
73 | 79 | let totalFee = (savedFee + fee) | |
74 | 80 | [IntegerEntry(totalFeeUsdKey, totalFee), ScriptTransfer(i.caller, dyzraptAmount, dyzraptAssetId)] | |
75 | 81 | } | |
76 | 82 | } | |
77 | 83 | ||
78 | 84 | ||
79 | 85 | ||
80 | 86 | @Callable(i) | |
81 | 87 | func swapEthToDyzrapt () = { | |
82 | 88 | let pmt = value(i.payments[0]) | |
83 | 89 | let assetId = pmt.assetId | |
84 | 90 | let totalAmount = pmt.amount | |
85 | 91 | if ((assetId != ethAssetId)) | |
86 | - | then throw("Only | |
92 | + | then throw("Only WETH tokens are allowed for swapping") | |
87 | 93 | else { | |
88 | 94 | let fee = getFeeAmount(totalAmount) | |
89 | 95 | let amount = (totalAmount - fee) | |
90 | 96 | let ethPrice = valueOrErrorMessage(getInteger(oracleAddress, priceOfEthKey), "Unable to load price") | |
91 | 97 | let usdnAmount = fraction(amount, ethPrice, 10000) | |
92 | 98 | let dyzraptAmount = usdnToDyzrapt(usdnAmount) | |
93 | 99 | let savedFee = getTotalFeeEth() | |
94 | 100 | let totalFee = (savedFee + fee) | |
95 | 101 | [IntegerEntry(totalFeeEthKey, totalFee), ScriptTransfer(i.caller, dyzraptAmount, dyzraptAssetId)] | |
96 | 102 | } | |
97 | 103 | } | |
98 | 104 | ||
99 | 105 | ||
106 | + | ||
107 | + | @Callable(i) | |
108 | + | func swapDyzraptToUsdn () = { | |
109 | + | let pmt = value(i.payments[0]) | |
110 | + | let assetId = pmt.assetId | |
111 | + | let totalAmount = pmt.amount | |
112 | + | if ((assetId != dyzraptAssetId)) | |
113 | + | then throw("Only DYZRAPT tokens are allowed for swapping") | |
114 | + | else { | |
115 | + | let fee = getFeeAmount(totalAmount) | |
116 | + | let amount = (totalAmount - fee) | |
117 | + | let usdnAmount = dyzraptToUsdn(amount) | |
118 | + | let savedFee = getTotalFeeDyzrapt() | |
119 | + | let totalFee = (savedFee + fee) | |
120 | + | [IntegerEntry(totalFeeUsdKey, totalFee), ScriptTransfer(i.caller, usdnAmount, usdnAssetId)] | |
121 | + | } | |
122 | + | } | |
123 | + | ||
124 | + |
github/deemru/w8io/169f3d6 36.70 ms ◑